From nitin.nitp at gmail.com Sun Mar 9 12:07:48 2014 From: nitin.nitp at gmail.com (Nitin Kumar) Date: Sun, 9 Mar 2014 16:37:48 +0530 Subject: [BangPypers] class instance getting passed to other class obj creation Message-ID: Hi All, I am looking for some better way to implement below scenario. Say there is a class login class login: def __init_(self, user, pwd): ----- now user uses this class to login a session and then I am using the object of this class being passed to other class. So that other class can use this logged in session. >>> lgn = login() >>> scores(lgn) >>> account(lgn) I am somehow not in favour of passing this object to different class. Is there a way such that once we have login object that is visible to other class. Nitin K From gora at mimirtech.com Sun Mar 9 13:02:15 2014 From: gora at mimirtech.com (Gora Mohanty) Date: Sun, 9 Mar 2014 17:32:15 +0530 Subject: [BangPypers] class instance getting passed to other class obj creation In-Reply-To: References: Message-ID: On 9 March 2014 16:37, Nitin Kumar wrote: > > Hi All, > > I am looking for some better way to implement below scenario. > > Say there is a class login > > class login: > def __init_(self, user, pwd): > ----- > > now user uses this class to login a session and then I am using the object > of this class being passed to other class. So that other class can use this > logged in session. > > >>> lgn = login() > >>> scores(lgn) > >>> account(lgn) > > I am somehow not in favour of passing this object to different class. Is > there a way such that once we have login object that is visible to other > class. How does your login work? What does the class store in order to validate login? Nowadays, this is typically an authentication token obtained with OAuth2, or the like. So, you could pass lgn.token to other functions that need authenticated services, though that is not very different from passing lgn itself. What is your objection to passing the login class instance? Alternatively, all services needing authentication could be part of a single class, where login() is a class method or derived from a base class. Regards, Gora From shyran at gmail.com Sun Mar 9 16:15:31 2014 From: shyran at gmail.com (shreyas) Date: Sun, 9 Mar 2014 20:45:31 +0530 Subject: [BangPypers] class instance getting passed to other class obj creation In-Reply-To: References: Message-ID: You could make login instance a module level variable and then use that as a singleton. shreyas On Mar 9, 2014 4:38 PM, "Nitin Kumar" wrote: > Hi All, > > I am looking for some better way to implement below scenario. > > Say there is a class login > > class login: > def __init_(self, user, pwd): > ----- > > now user uses this class to login a session and then I am using the object > of this class being passed to other class. So that other class can use this > logged in session. > > >>> lgn = login() > >>> scores(lgn) > >>> account(lgn) > > I am somehow not in favour of passing this object to different class. Is > there a way such that once we have login object that is visible to other > class. > > > Nitin K > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers > From venkat83 at gmail.com Sat Mar 8 09:39:06 2014 From: venkat83 at gmail.com (Venkatraman S) Date: Sat, 8 Mar 2014 14:09:06 +0530 Subject: [BangPypers] Fwd: [Baypiggies] PyLadies: Get paid to contribute to Python this Summer In-Reply-To: <86B0F43A-F2A0-4BA9-A483-AA6A948B8193@lynnroot.com> References: <86B0F43A-F2A0-4BA9-A483-AA6A948B8193@lynnroot.com> Message-ID: FYI: Regards, Venkat @venkasub ---------- Forwarded message ---------- From: Lynn Root Date: Thu, Mar 6, 2014 at 12:31 AM Subject: [Baypiggies] PyLadies: Get paid to contribute to Python this Summer To: baypiggies at python.org Hey folks - The PSF is sponsoring CPython internships for women this summer through the GNOME Outreach Program for Women. Folks selected will receive $5500 USD stipend for contributing to the CPython interpreter & standard lib. More info 1 . No need to be a super Pythonista or know C, there are a lot of opportunities to contribute for every level of experience. I am one of the mentors for the project - and there will be a workshop via IRC this Sunday for those interested in learning about the process so they can apply to the program. More info 2 . Please pass around to anyone who you feel would be interested! LR _______________________________________________ Baypiggies mailing list Baypiggies at python.org To change your subscription options or unsubscribe: https://mail.python.org/mailman/listinfo/baypiggies From dileep.ds at gmail.com Sun Mar 9 17:41:13 2014 From: dileep.ds at gmail.com (Dileep) Date: Sun, 9 Mar 2014 22:11:13 +0530 Subject: [BangPypers] Need Python Developer (5- 7 years Exp) Message-ID: Hi, We require Python Developer for our company Hewlett-Packard India Software Operation. This requirement is for our R&D division Bangalore. If you are interested please send me your resume to dileep.ds at gmail.com -- Regards D.S. DIleep From noufal at nibrahim.net.in Sun Mar 9 18:22:00 2014 From: noufal at nibrahim.net.in (Noufal Ibrahim KV) Date: Sun, 09 Mar 2014 22:52:00 +0530 Subject: [BangPypers] Need Python Developer (5- 7 years Exp) In-Reply-To: (Dileep's message of "Sun, 9 Mar 2014 22:11:13 +0530") References: Message-ID: <871tybgudj.fsf@sanitarium.localdomain> On Sun, Mar 09 2014, Dileep wrote: > Hi, > > We require Python Developer for our company Hewlett-Packard India Software > Operation. > This requirement is for our R&D division Bangalore. If you are interested > please send me your resume to dileep.ds at gmail.com It might be a good idea to describe what the kind of role which you're looking to fill. -- Cordially, Noufal http://nibrahim.net.in From karra.etc at gmail.com Mon Mar 10 04:26:30 2014 From: karra.etc at gmail.com (Sriram Karra) Date: Mon, 10 Mar 2014 08:56:30 +0530 Subject: [BangPypers] class instance getting passed to other class obj creation In-Reply-To: References: Message-ID: If your login is a simple action I would not even make it a separate class. You should revisit your class hierarchy. On Mar 9, 2014 4:38 PM, "Nitin Kumar" wrote: > Hi All, > > I am looking for some better way to implement below scenario. > > Say there is a class login > > class login: > def __init_(self, user, pwd): > ----- > > now user uses this class to login a session and then I am using the object > of this class being passed to other class. So that other class can use this > logged in session. > > >>> lgn = login() > >>> scores(lgn) > >>> account(lgn) > > I am somehow not in favour of passing this object to different class. Is > there a way such that once we have login object that is visible to other > class. > > > Nitin K > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers > From shashidhar85 at gmail.com Mon Mar 10 11:09:39 2014 From: shashidhar85 at gmail.com (Shashidhar Paragonda) Date: Mon, 10 Mar 2014 15:39:39 +0530 Subject: [BangPypers] { Parsing excel file } Message-ID: >>> Hello python hackers >>> I have a excel file which is .xls format. >>> My requirement is: the excel file contains a manual test cases, in second column, I need to read a file and extract thekeywords like : Login, logout, click to optimize, enhance, so on. >>> any suggestions on how to parse the keywords or can we parse italized / bolded words. >>> any suggestions on python library to work on such requirement ? ----------------------------------- Regards, Shashidhar N.Paragonda shashidhar85 at gmail.com +919900093835 From noufal at nibrahim.net.in Mon Mar 10 11:29:10 2014 From: noufal at nibrahim.net.in (Noufal Ibrahim KV) Date: Mon, 10 Mar 2014 15:59:10 +0530 Subject: [BangPypers] { Parsing excel file } In-Reply-To: (Shashidhar Paragonda's message of "Mon, 10 Mar 2014 15:39:39 +0530") References: Message-ID: <87r46ae495.fsf@sanitarium.localdomain> On Mon, Mar 10 2014, Shashidhar Paragonda wrote: > Hello python hackers > > I have a excel file which is .xls format. My requirement is: the > excel file contains a manual test cases, in second column, I need to > read a file and extract thekeywords like : Login, logout, click to > optimize, enhance, so on. any suggestions on how to parse the > keywords or can we parse italized / bolded words. any suggestions on > python library to work on such requirement ? I can see a few. % pip search excel | grep -iw excel | wc -l 38 One of those might be useful. xlwt is something I've used in the past. [...] -- Cordially, Noufal http://nibrahim.net.in From modi.konark at gmail.com Mon Mar 10 12:51:31 2014 From: modi.konark at gmail.com (konark modi) Date: Mon, 10 Mar 2014 17:21:31 +0530 Subject: [BangPypers] { Parsing excel file } In-Reply-To: <87r46ae495.fsf@sanitarium.localdomain> References: <87r46ae495.fsf@sanitarium.localdomain> Message-ID: Hi For parsing .xls files with Python, I've used xlrd lib ( https://pypi.python.org/pypi/xlrd) quite extensively. Let's you move around multiple sheets aswell and parse data easily. Regards Konark On Mon, Mar 10, 2014 at 3:59 PM, Noufal Ibrahim KV wrote: > On Mon, Mar 10 2014, Shashidhar Paragonda wrote: > > > Hello python hackers > > > > I have a excel file which is .xls format. My requirement is: the > > excel file contains a manual test cases, in second column, I need to > > read a file and extract thekeywords like : Login, logout, click to > > optimize, enhance, so on. any suggestions on how to parse the > > keywords or can we parse italized / bolded words. any suggestions on > > python library to work on such requirement ? > > I can see a few. > % pip search excel | grep -iw excel | wc -l > 38 > > One of those might be useful. xlwt is something I've used in the past. > > [...] > > > -- > Cordially, > Noufal > http://nibrahim.net.in > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers > From karthik_prakash1984 at yahoo.co.in Mon Mar 10 14:01:49 2014 From: karthik_prakash1984 at yahoo.co.in (karthik prakash) Date: Mon, 10 Mar 2014 21:01:49 +0800 (SGT) Subject: [BangPypers] { Parsing excel file } In-Reply-To: References: <87r46ae495.fsf@sanitarium.localdomain> Message-ID: <1394456509.46424.YahooMailNeo@web193702.mail.sg3.yahoo.com> Hi, There are a couple of options, for excel connectivity in Python. XLRD :- Reading from XLS and XLSX files. XLWT :- Writing to XLS files (currently no support for XLSX) OPENPYXL :- Read and Write only XLSX file. (No support for XLS) Regards, Karthik ? On Monday, 10 March 2014 5:21 PM, konark modi wrote: Hi For parsing .xls files with Python, I've used xlrd lib ( https://pypi.python.org/pypi/xlrd) quite extensively. Let's you move around multiple sheets aswell and parse data easily. Regards Konark On Mon, Mar 10, 2014 at 3:59 PM, Noufal Ibrahim KV wrote: > On Mon, Mar 10 2014, Shashidhar Paragonda wrote: > > > Hello python hackers > > > > I have a excel file which is .xls format.? My requirement is: the > > excel file contains a manual test cases, in second column, I need to > > read a file and extract thekeywords like : Login, logout, click to > > optimize, enhance, so on.? any suggestions on how to parse the > > keywords or can we parse italized / bolded words.? any suggestions on > > python library to work on such requirement ? > > I can see a few. > % pip search excel | grep -iw excel | wc -l > 38 > > One of those might be useful. xlwt is something I've used in the past. > > [...] > > > -- > Cordially, > Noufal > http://nibrahim.net.in > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers > _______________________________________________ BangPypers mailing list BangPypers at python.org https://mail.python.org/mailman/listinfo/bangpypers From mandarvaze at gmail.com Mon Mar 10 14:14:28 2014 From: mandarvaze at gmail.com (=?UTF-8?B?TWFuZGFyIFZhemUgLyDgpK7gpILgpKbgpL7gpLAg4KS14KSd4KWH?=) Date: Mon, 10 Mar 2014 18:44:28 +0530 Subject: [BangPypers] { Parsing excel file } In-Reply-To: <1394456509.46424.YahooMailNeo@web193702.mail.sg3.yahoo.com> References: <87r46ae495.fsf@sanitarium.localdomain> <1394456509.46424.YahooMailNeo@web193702.mail.sg3.yahoo.com> Message-ID: > OPENPYXL :- Read and Write only XLSX file. (No support for XLS) > We are using openpyxl in our product - mainly because we needed to *create* xlsx files. -Mandar From shashidhar85 at gmail.com Wed Mar 12 05:59:36 2014 From: shashidhar85 at gmail.com (Shashidhar Paragonda) Date: Wed, 12 Mar 2014 10:29:36 +0530 Subject: [BangPypers] { exctract italic, bold } Message-ID: Hello Python hackers >>> I have a excel file which has some amount of data. >>> The data in each row has some words which are italic and bolded. >>> my requirement is I need to extract only italic or bold words from each row. >>> any suggestions on the same, thank you in advance. ----------------------------------- Regards, Shashidhar N.Paragonda shashidhar85 at gmail.com +919900093835 From shankhabanerjee at gmail.com Wed Mar 12 06:05:10 2014 From: shankhabanerjee at gmail.com (shankha) Date: Wed, 12 Mar 2014 10:35:10 +0530 Subject: [BangPypers] { exctract italic, bold } In-Reply-To: References: Message-ID: I have used a package called xlutils to generate excel files. Never had the need to read back something. Check if it has API's for reading as well. I would be surprised if ti doesn't. Thanks Shankha Banerjee On Wed, Mar 12, 2014 at 10:29 AM, Shashidhar Paragonda wrote: > Hello Python hackers > >>>> I have a excel file which has some amount of data. >>>> The data in each row has some words which are italic and bolded. >>>> my requirement is I need to extract only italic or bold words from each > row. >>>> any suggestions on the same, thank you in advance. > > ----------------------------------- > Regards, > > Shashidhar N.Paragonda > shashidhar85 at gmail.com > +919900093835 > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers From shankhabanerjee at gmail.com Wed Mar 12 06:07:22 2014 From: shankhabanerjee at gmail.com (shankha) Date: Wed, 12 Mar 2014 10:37:22 +0530 Subject: [BangPypers] { exctract italic, bold } In-Reply-To: References: Message-ID: Will it work if you just search for a string instead of Italics or bold. That may be easier, if you have a fixed set of strings. If you are dealing with numbers it is much simpler. Thanks Shankha Banerjee On Wed, Mar 12, 2014 at 10:35 AM, shankha wrote: > I have used a package called xlutils to generate excel files. Never > had the need to read back something. Check if it has API's for reading > as well. I would be surprised if ti doesn't. > Thanks > Shankha Banerjee > > > On Wed, Mar 12, 2014 at 10:29 AM, Shashidhar Paragonda > wrote: >> Hello Python hackers >> >>>>> I have a excel file which has some amount of data. >>>>> The data in each row has some words which are italic and bolded. >>>>> my requirement is I need to extract only italic or bold words from each >> row. >>>>> any suggestions on the same, thank you in advance. >> >> ----------------------------------- >> Regards, >> >> Shashidhar N.Paragonda >> shashidhar85 at gmail.com >> +919900093835 >> _______________________________________________ >> BangPypers mailing list >> BangPypers at python.org >> https://mail.python.org/mailman/listinfo/bangpypers From shashidhar85 at gmail.com Wed Mar 12 06:25:51 2014 From: shashidhar85 at gmail.com (Shashidhar Paragonda) Date: Wed, 12 Mar 2014 10:55:51 +0530 Subject: [BangPypers] { exctract italic, bold } In-Reply-To: References: Message-ID: hi >>> Well the data in each row are the manual test case steps, >>> each row will have different italised, bold words! this is main constaint. >>> My main concerns is manual test cases are generated by us. >>> We need to follow some standard were i need to extract keywords like: Login, logout, click on capture button, print, center, so on.... >>> I thought making such keywords either italic or bold ( any other suggestions you have for this ) so i can fetch them and send it to automation test tool like: TestComplete, for further execution of each test case. ----------------------------------- Regards, Shashidhar N.Paragonda shashidhar85 at gmail.com +919900093835 On Wed, Mar 12, 2014 at 10:37 AM, shankha wrote: > Will it work if you just search for a string instead of Italics or > bold. That may be easier, if you have a fixed set of strings. > If you are dealing with numbers it is much simpler. > Thanks > Shankha Banerjee > > > On Wed, Mar 12, 2014 at 10:35 AM, shankha > wrote: > > I have used a package called xlutils to generate excel files. Never > > had the need to read back something. Check if it has API's for reading > > as well. I would be surprised if ti doesn't. > > Thanks > > Shankha Banerjee > > > > > > On Wed, Mar 12, 2014 at 10:29 AM, Shashidhar Paragonda > > wrote: > >> Hello Python hackers > >> > >>>>> I have a excel file which has some amount of data. > >>>>> The data in each row has some words which are italic and bolded. > >>>>> my requirement is I need to extract only italic or bold words from > each > >> row. > >>>>> any suggestions on the same, thank you in advance. > >> > >> ----------------------------------- > >> Regards, > >> > >> Shashidhar N.Paragonda > >> shashidhar85 at gmail.com > >> +919900093835 > >> _______________________________________________ > >> BangPypers mailing list > >> BangPypers at python.org > >> https://mail.python.org/mailman/listinfo/bangpypers > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers > From shashidhar85 at gmail.com Wed Mar 12 06:26:00 2014 From: shashidhar85 at gmail.com (Shashidhar Paragonda) Date: Wed, 12 Mar 2014 10:56:00 +0530 Subject: [BangPypers] { exctract italic, bold } In-Reply-To: References: Message-ID: hi >>> Well the data in each row are the manual test case steps, >>> each row will have different italised, bold words! this is main constaint. >>> My main concerns is manual test cases are generated by us. >>> We need to follow some standard were i need to extract keywords like: Login, logout, click on capture button, print, center, so on.... >>> I thought making such keywords either italic or bold ( any other suggestions you have for this ) so i can fetch them and send it to automation test tool like: TestComplete, for further execution of each test case. ----------------------------------- Regards, Shashidhar N.Paragonda shashidhar85 at gmail.com +919900093835 On Wed, Mar 12, 2014 at 10:37 AM, shankha wrote: > Will it work if you just search for a string instead of Italics or > bold. That may be easier, if you have a fixed set of strings. > If you are dealing with numbers it is much simpler. > Thanks > Shankha Banerjee > > > On Wed, Mar 12, 2014 at 10:35 AM, shankha > wrote: > > I have used a package called xlutils to generate excel files. Never > > had the need to read back something. Check if it has API's for reading > > as well. I would be surprised if ti doesn't. > > Thanks > > Shankha Banerjee > > > > > > On Wed, Mar 12, 2014 at 10:29 AM, Shashidhar Paragonda > > wrote: > >> Hello Python hackers > >> > >>>>> I have a excel file which has some amount of data. > >>>>> The data in each row has some words which are italic and bolded. > >>>>> my requirement is I need to extract only italic or bold words from > each > >> row. > >>>>> any suggestions on the same, thank you in advance. > >> > >> ----------------------------------- > >> Regards, > >> > >> Shashidhar N.Paragonda > >> shashidhar85 at gmail.com > >> +919900093835 > >> _______________________________________________ > >> BangPypers mailing list > >> BangPypers at python.org > >> https://mail.python.org/mailman/listinfo/bangpypers > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers > From gora at mimirtech.com Wed Mar 12 06:28:35 2014 From: gora at mimirtech.com (Gora Mohanty) Date: Wed, 12 Mar 2014 10:58:35 +0530 Subject: [BangPypers] { exctract italic, bold } In-Reply-To: References: Message-ID: On 12 March 2014 10:29, Shashidhar Paragonda wrote: > > Hello Python hackers > > >>> I have a excel file which has some amount of data. > >>> The data in each row has some words which are italic and bolded. > >>> my requirement is I need to extract only italic or bold words from each > row. > >>> any suggestions on the same, thank you in advance. Try xlrd. This includes style information from the Excel file. We have used it to pick out underlined fonts, so I imagine that bold/italic should also be possible. Please check the documentation. Regards, Gora From shashidhar85 at gmail.com Thu Mar 13 06:05:04 2014 From: shashidhar85 at gmail.com (Shashidhar Paragonda) Date: Thu, 13 Mar 2014 10:35:04 +0530 Subject: [BangPypers] { exctract italic, bold } In-Reply-To: References: Message-ID: Hello, Thanks for the help, I read the doc there is bold, italic under font class. I am unable to figure out how to fetch the bold or italic words. Could you please share code how you implemented for fetching underlined words. ----------------------------------- Regards, Shashidhar N.Paragonda shashidhar85 at gmail.com +919900093835 On Wed, Mar 12, 2014 at 10:58 AM, Gora Mohanty wrote: > On 12 March 2014 10:29, Shashidhar Paragonda > wrote: > > > > Hello Python hackers > > > > >>> I have a excel file which has some amount of data. > > >>> The data in each row has some words which are italic and bolded. > > >>> my requirement is I need to extract only italic or bold words from > each > > row. > > >>> any suggestions on the same, thank you in advance. > > Try xlrd. This includes style information from the Excel file. We have used > it to pick out underlined fonts, so I imagine that bold/italic should also > be possible. Please check the documentation. > > Regards, > Gora > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers > From kartiksinghal at gmail.com Mon Mar 17 03:16:23 2014 From: kartiksinghal at gmail.com (Kartik Singhal) Date: Mon, 17 Mar 2014 07:46:23 +0530 Subject: [BangPypers] Fwd: [Ncr-Python.in] Kivy programming contest 2014 In-Reply-To: References: Message-ID: ---------- Forwarded message ---------- From: qua-non non Date: Mon, Mar 17, 2014 at 3:18 AM Subject: [Ncr-Python.in] Kivy programming contest 2014 To: NCR Python Users Group India 2nd Kivy Contest Kivy is organizing its second application development contest! starting April 15th 2014. This is a call for users interested in taking part, get ready to compete for fabulous prizes (to be announced before the start of the contest). [image: Kivy will be holding it's next contest starting April 15th 2014. This is a call for users interested in taking part, get ready to compete for fabulous prizes (to be announced soon). http://kivy.org/#contest Sponsors interested in being a part of the contest can contact us at contest at kivy.org.] About Kivy: Kivy is an open source Python framework for the rapid development of multi-touch, multi-platform (Android, iOS, Windows, OSX, and Linux) Applications with OpenGL ES 2.0 accelerated graphics for it?s UX. Contest details: Guidelines(Specific details and rules will be announced before the start of the contest) - Keep it family friendly. - Make it fun, attractive. - Entries can be for individual or a team. - No prior code, contestants should start coding from scratch on the contest start date and stop at contest end date. - Apps should be submitted before 15th May 23:59 GMT using a github url Important Dates - Start accepting entries: 2nd April 2014 - Final registration deadline 13th April 2014 - Announcement of Prizes. 15th April.2014 - Start of contest : 15th April 2014 - Contest completion date: 15th May 2014 - Winners announcement. 20th May 2014 You can see the entries of the last gaming contest here For a list of apps made using kivy you can look at wiki.kivy.org Sponsors interested in being a part of the contest can contact us at contest at kivy.org. _______________________________________________ https://mail.python.org/mailman/listinfo/ncr-python.in Mailing list guidelines : http://python.org.in/wiki/NcrPython/MailingListGuidelines -- Kartik http://k4rtik.wordpress.com/ From saurabh.minni at gmail.com Sun Mar 16 16:51:58 2014 From: saurabh.minni at gmail.com (Saurabh Minni) Date: Sun, 16 Mar 2014 21:21:58 +0530 Subject: [BangPypers] Fwd: [BCB] Registrations Open for Barcamp Bangalore Spring 2014 ! In-Reply-To: References: Message-ID: Hi Friends, Registrations for Barcamp Bangalore Spring 2014 scheduled for 29th March 2014 is now open. Please read the details below. Thanks, Saurabh ---------- Forwarded message ---------- From: Aman Manglik Date: Thu, Mar 13, 2014 at 11:52 AM Subject: [BCB] Registrations Open for Barcamp Bangalore Spring 2014 ! To: bangalore_barcamp at yahoogroups.com Hi Campers Its that time again... To come together to discuss and talk about your interests and passions with a community of your enlightened peers. We announce the opening of registrations for *Barcamp Bangalore Spring 2014* on* 29th March at SAP Labs, Whitefield*. Please visit http://barcampbangalore.org/bcb/ to register and put in your sessions. *To Register* - Create an account on the site. You can also login using your other accounts like google, facebook, OpenID etc. Veterans can use their existing account. - To register for BCB Spring 2014, mark the sessions you want to attend by clicking on "I wanna Attend" buttons for those sessions. Your registration will be automatically counted as long as you are attending any session. - In Barcamp anyone can talk about anything. So find something interesting to talk about and Add a Session ! Believe us, Everyone will love to hear from you and discuss with you. Thats the spirit of Barcamp. Spread the word and feel free to reach out to the barcamp community :) Cheers Aman From lokeshbobbys at yahoo.com Fri Mar 21 09:18:40 2014 From: lokeshbobbys at yahoo.com (lokesh bobby) Date: Fri, 21 Mar 2014 16:18:40 +0800 (SGT) Subject: [BangPypers] JSON PARSER Message-ID: <1395389920.23044.YahooMailNeo@web193806.mail.sg3.yahoo.com> Hi ALL, Can you share your thoughts on how to parse a JSON file by using python? Thanks, Lokesh. From noufal at nibrahim.net.in Fri Mar 21 09:38:27 2014 From: noufal at nibrahim.net.in (Noufal Ibrahim KV) Date: Fri, 21 Mar 2014 14:08:27 +0530 Subject: [BangPypers] JSON PARSER In-Reply-To: <1395389920.23044.YahooMailNeo@web193806.mail.sg3.yahoo.com> (lokesh bobby's message of "Fri, 21 Mar 2014 16:18:40 +0800 (SGT)") References: <1395389920.23044.YahooMailNeo@web193806.mail.sg3.yahoo.com> Message-ID: <878us4c5fg.fsf@sanitarium.localdomain> On Fri, Mar 21 2014, lokesh bobby wrote: > Hi ALL, > > Can you share your thoughts on how to parse a JSON file by using > python? import json with open("data.json") as f: json.load(f) [...] -- Cordially, Noufal http://nibrahim.net.in From 91prashantgaur at gmail.com Fri Mar 21 10:00:19 2014 From: 91prashantgaur at gmail.com (Prashant Gaur) Date: Fri, 21 Mar 2014 14:30:19 +0530 Subject: [BangPypers] JSON PARSER In-Reply-To: <878us4c5fg.fsf@sanitarium.localdomain> References: <1395389920.23044.YahooMailNeo@web193806.mail.sg3.yahoo.com> <878us4c5fg.fsf@sanitarium.localdomain> Message-ID: Python provides json module to parse JSON files. import json from pprint import pprint with open('data.json') as json_file: data = json.load(json_file) pprint(data) Here i am using pprint to print result data (You can have a look http://docs.python.org/2/library/pprint.html ) Or You can also use simplejson library to do same . ( http://simplejson.readthedocs.org/en/latest/ ) On Fri, Mar 21, 2014 at 2:08 PM, Noufal Ibrahim KV wrote: > On Fri, Mar 21 2014, lokesh bobby wrote: > > > Hi ALL, > > > > Can you share your thoughts on how to parse a JSON file by using > > python? > > import json > > with open("data.json") as f: > json.load(f) > > > [...] > > > -- > Cordially, > Noufal > http://nibrahim.net.in > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers > -- Prashant Gaur Mobile : +91 9717353657 http://gaurprashant.blogspot.in/ http://stackoverflow.com/users/1850358/prashant-gaur http://www.about.me/prashantgaur/ From vsapre80 at gmail.com Fri Mar 21 10:01:38 2014 From: vsapre80 at gmail.com (Vishal) Date: Fri, 21 Mar 2014 14:31:38 +0530 Subject: [BangPypers] JSON PARSER In-Reply-To: <878us4c5fg.fsf@sanitarium.localdomain> References: <1395389920.23044.YahooMailNeo@web193806.mail.sg3.yahoo.com> <878us4c5fg.fsf@sanitarium.localdomain> Message-ID: Hi, I have used simplejson and ultrajson. Found ultrajson to be the fastest amongst known libraries for Python UltraJSON ( http://pushingtheweb.com/2011/03/ultra-fast-json-encoding-decoding-python/) Compare performance: http://stackoverflow.com/a/15440843 Download it from here: https://pypi.python.org/pypi/ujson/ Take care, Vishal Thanks and best regards, Vishal Sapre --- "Life is 10% how you make it, and 90% how you take it" "????? ?????, ????? ????? (Benefit for most people, Happiness for most people.)" --- Please DONT print this email, unless you really need to. Save Energy & Paper. Save the Earth. On Fri, Mar 21, 2014 at 2:08 PM, Noufal Ibrahim KV wrote: > On Fri, Mar 21 2014, lokesh bobby wrote: > > > Hi ALL, > > > > Can you share your thoughts on how to parse a JSON file by using > > python? > > import json > > with open("data.json") as f: > json.load(f) > > > [...] > > > -- > Cordially, > Noufal > http://nibrahim.net.in > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers > From lokeshbobbys at yahoo.com Fri Mar 21 10:00:03 2014 From: lokeshbobbys at yahoo.com (lokesh bobby) Date: Fri, 21 Mar 2014 17:00:03 +0800 (SGT) Subject: [BangPypers] JSON PARSER In-Reply-To: <878us4c5fg.fsf@sanitarium.localdomain> References: <1395389920.23044.YahooMailNeo@web193806.mail.sg3.yahoo.com> <878us4c5fg.fsf@sanitarium.localdomain> Message-ID: <1395392403.5407.YahooMailNeo@web193803.mail.sg3.yahoo.com> Hi Noufal, Thanks for your reply. I am not looking for loading the JSON file. There is a limitation in it. Go thru the links http://docs.python.org/2/library/json.html#repeated-names-within-an-object http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object In order to get rid of that problem, I am looking for some JSON stream parsers. Thanks, Lokesh. On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV wrote: On Fri, Mar 21 2014, lokesh bobby wrote: > Hi ALL, > > Can you share your thoughts on how to parse a JSON file by using > python? import json with open("data.json") as f: ? ? json.load(f) [...] -- Cordially, Noufal http://nibrahim.net.in From jnkoushik at gmail.com Fri Mar 21 10:15:19 2014 From: jnkoushik at gmail.com (Jayanth Koushik) Date: Fri, 21 Mar 2014 14:45:19 +0530 Subject: [BangPypers] JSON PARSER In-Reply-To: <1395392403.5407.YahooMailNeo@web193803.mail.sg3.yahoo.com> References: <1395389920.23044.YahooMailNeo@web193806.mail.sg3.yahoo.com> <878us4c5fg.fsf@sanitarium.localdomain> <1395392403.5407.YahooMailNeo@web193803.mail.sg3.yahoo.com> Message-ID: Hi Lokesh The 'problem' that you talk about isn't really a problem. Since the JSON specification does not say what is to be done for repeated names, it is up to the implementation to decide. What is your requirement for handling repeated names? Jayanth On Fri, Mar 21, 2014 at 2:30 PM, lokesh bobby wrote: > Hi Noufal, > > Thanks for your reply. I am not looking for loading the JSON file. There > is a limitation in it. Go thru the links > > http://docs.python.org/2/library/json.html#repeated-names-within-an-object > > http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object > > In order to get rid of that problem, I am looking for some JSON stream > parsers. > > Thanks, > Lokesh. > > > > On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV < > noufal at nibrahim.net.in> wrote: > > On Fri, Mar 21 2014, lokesh bobby wrote: > > > > Hi ALL, > > > > Can you share your thoughts on how to parse a JSON file by using > > python? > > import json > > with open("data.json") as f: > json.load(f) > > > [...] > > > -- > Cordially, > Noufal > http://nibrahim.net.in > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers > From lokeshbobbys at yahoo.com Fri Mar 21 10:29:11 2014 From: lokeshbobbys at yahoo.com (lokesh bobby) Date: Fri, 21 Mar 2014 17:29:11 +0800 (SGT) Subject: [BangPypers] JSON PARSER In-Reply-To: References: <1395389920.23044.YahooMailNeo@web193806.mail.sg3.yahoo.com> <878us4c5fg.fsf@sanitarium.localdomain> <1395392403.5407.YahooMailNeo@web193803.mail.sg3.yahoo.com> Message-ID: <1395394151.2035.YahooMailNeo@web193801.mail.sg3.yahoo.com> Hi Jayanth, Ideally speaking a JSON shouldn't be created with repetitive key names. But manually it is possible that a proper JSON file can be appended with a duplicate key. We need to catch that duplicate key. If we are going to use json.load(), the repetitive keys of the JSON file wont get loaded. Only the last occurrence of the key will be there in that loaded data. Instead I want that entire data in JSON file should be loaded. Hoping that you got the point what I want :-) Thanks, Lokesh. On Friday, 21 March 2014 2:45 PM, Jayanth Koushik wrote: Hi Lokesh The 'problem' that you talk about isn't really a problem. Since the JSON specification does not say what is to be done for repeated names, it is up to the implementation to decide. What is your requirement for handling repeated names? Jayanth On Fri, Mar 21, 2014 at 2:30 PM, lokesh bobby wrote: Hi Noufal, > >Thanks for your reply. I am not looking for loading the JSON file. There is a limitation in it. Go thru the links > >http://docs.python.org/2/library/json.html#repeated-names-within-an-object >http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object > >In order to get rid of that problem, I am looking for some JSON stream parsers. > >Thanks, >Lokesh. > > > > >On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV wrote: > >On Fri, Mar 21 2014, lokesh bobby wrote: > > >> Hi ALL, >> >> Can you share your thoughts on how to parse a JSON file by using >> python? > >import json > >with open("data.json") as f: >? ? ?json.load(f) > > >[...] > > >-- >Cordially, >Noufal >http://nibrahim.net.in >_______________________________________________ >BangPypers mailing list >BangPypers at python.org >https://mail.python.org/mailman/listinfo/bangpypers > From 91prashantgaur at gmail.com Fri Mar 21 10:45:47 2014 From: 91prashantgaur at gmail.com (Prashant Gaur) Date: Fri, 21 Mar 2014 15:15:47 +0530 Subject: [BangPypers] JSON PARSER In-Reply-To: <1395394151.2035.YahooMailNeo@web193801.mail.sg3.yahoo.com> References: <1395389920.23044.YahooMailNeo@web193806.mail.sg3.yahoo.com> <878us4c5fg.fsf@sanitarium.localdomain> <1395392403.5407.YahooMailNeo@web193803.mail.sg3.yahoo.com> <1395394151.2035.YahooMailNeo@web193801.mail.sg3.yahoo.com> Message-ID: Hi Lokesh, we can pass lookup while parsing your json file which will make sure that name is repetitive or not . import json def duplicate_checking_hook(pairs): ''' lookup for duplicate names''' result = dict() for key, val in pairs: if key in result: raise KeyError('Duplicate Key specified: %s % key) result[key] = val return result >>> json.loads('''{"test":"hi","test":"bye"}''', object_pairs_hook=duplicate_checking_hook) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/json/__init__.py", line 339, in loads return cls(encoding=encoding, **kw).decode(s) File "/usr/lib/python2.7/json/decoder.py", line 366, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode obj, end = self.scan_once(s, idx) File "", line 5, in duplicate_checking_hook KeyError: u'Duplicate key specified: a' While >>> json.loads('''{"test":"hi","test1":"bye"}''', object_pairs_hook=duplicate_checking_hook) {u'test': u'hi', u'test1': u'bye'} >>> def dupe_checking_hook(pairs): result = dict() for key,val in pairs: if key in result: raise KeyError("Duplicate key specified: %s" % key) result[key] = val return result On Fri, Mar 21, 2014 at 2:59 PM, lokesh bobby wrote: > Hi Jayanth, > > Ideally speaking a JSON shouldn't be created with repetitive key names. > But manually it is possible that a proper JSON file can be appended with a > duplicate key. We need to catch that duplicate key. If we are going to use > json.load(), the repetitive keys of the JSON file wont get loaded. Only the > last occurrence of the key will be there in that loaded data. > > Instead I want that entire data in JSON file should be loaded. Hoping that > you got the point what I want :-) > > Thanks, > Lokesh. > > > > > > On Friday, 21 March 2014 2:45 PM, Jayanth Koushik > wrote: > > Hi Lokesh > > > The 'problem' that you talk about isn't really a problem. Since the JSON > specification does not say what is to be done for repeated names, it is up > to the implementation to decide. What is your requirement for handling > repeated names? > > > Jayanth > > > > > On Fri, Mar 21, 2014 at 2:30 PM, lokesh bobby > wrote: > > Hi Noufal, > > > >Thanks for your reply. I am not looking for loading the JSON file. There > is a limitation in it. Go thru the links > > > > > http://docs.python.org/2/library/json.html#repeated-names-within-an-object > > > http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object > > > >In order to get rid of that problem, I am looking for some JSON stream > parsers. > > > >Thanks, > >Lokesh. > > > > > > > > > >On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV < > noufal at nibrahim.net.in> wrote: > > > >On Fri, Mar 21 2014, lokesh bobby wrote: > > > > > >> Hi ALL, > >> > >> Can you share your thoughts on how to parse a JSON file by using > >> python? > > > >import json > > > >with open("data.json") as f: > > json.load(f) > > > > > >[...] > > > > > >-- > >Cordially, > >Noufal > >http://nibrahim.net.in > >_______________________________________________ > >BangPypers mailing list > >BangPypers at python.org > >https://mail.python.org/mailman/listinfo/bangpypers > > > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers > -- Prashant Gaur Mobile : +91 9717353657 http://gaurprashant.blogspot.in/ http://stackoverflow.com/users/1850358/prashant-gaur http://www.about.me/prashantgaur/ From jnkoushik at gmail.com Fri Mar 21 10:47:48 2014 From: jnkoushik at gmail.com (Jayanth Koushik) Date: Fri, 21 Mar 2014 15:17:48 +0530 Subject: [BangPypers] JSON PARSER In-Reply-To: References: <1395389920.23044.YahooMailNeo@web193806.mail.sg3.yahoo.com> <878us4c5fg.fsf@sanitarium.localdomain> <1395392403.5407.YahooMailNeo@web193803.mail.sg3.yahoo.com> <1395394151.2035.YahooMailNeo@web193801.mail.sg3.yahoo.com> Message-ID: Hi Prashant I think he wants the duplicates to be loaded, not cause an exception. Jayanth On Fri, Mar 21, 2014 at 3:15 PM, Prashant Gaur <91prashantgaur at gmail.com>wrote: > Hi Lokesh, > > we can pass lookup while parsing your json file which will make sure that > name is repetitive or not . > > import json > > def duplicate_checking_hook(pairs): > ''' lookup for duplicate names''' > result = dict() > for key, val in pairs: > if key in result: > raise KeyError('Duplicate Key specified: %s % key) > result[key] = val > return result > > >>> json.loads('''{"test":"hi","test":"bye"}''', > object_pairs_hook=duplicate_checking_hook) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.7/json/__init__.py", line 339, in loads > return cls(encoding=encoding, **kw).decode(s) > File "/usr/lib/python2.7/json/decoder.py", line 366, in decode > obj, end = self.raw_decode(s, idx=_w(s, 0).end()) > File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode > obj, end = self.scan_once(s, idx) > File "", line 5, in duplicate_checking_hook > KeyError: u'Duplicate key specified: a' > > While > > >>> json.loads('''{"test":"hi","test1":"bye"}''', > object_pairs_hook=duplicate_checking_hook) > {u'test': u'hi', u'test1': u'bye'} > >>> > > > > def dupe_checking_hook(pairs): > result = dict() > for key,val in pairs: > if key in result: > raise KeyError("Duplicate key specified: %s" % key) > result[key] = val > return result > > > > > > On Fri, Mar 21, 2014 at 2:59 PM, lokesh bobby wrote: > >> Hi Jayanth, >> >> Ideally speaking a JSON shouldn't be created with repetitive key names. >> But manually it is possible that a proper JSON file can be appended with a >> duplicate key. We need to catch that duplicate key. If we are going to use >> json.load(), the repetitive keys of the JSON file wont get loaded. Only the >> last occurrence of the key will be there in that loaded data. >> >> Instead I want that entire data in JSON file should be loaded. Hoping >> that you got the point what I want :-) >> >> Thanks, >> Lokesh. >> >> >> >> >> >> On Friday, 21 March 2014 2:45 PM, Jayanth Koushik >> wrote: >> >> Hi Lokesh >> >> >> The 'problem' that you talk about isn't really a problem. Since the JSON >> specification does not say what is to be done for repeated names, it is up >> to the implementation to decide. What is your requirement for handling >> repeated names? >> >> >> Jayanth >> >> >> >> >> On Fri, Mar 21, 2014 at 2:30 PM, lokesh bobby >> wrote: >> >> Hi Noufal, >> > >> >Thanks for your reply. I am not looking for loading the JSON file. There >> is a limitation in it. Go thru the links >> > >> > >> http://docs.python.org/2/library/json.html#repeated-names-within-an-object >> > >> http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object >> > >> >In order to get rid of that problem, I am looking for some JSON stream >> parsers. >> > >> >Thanks, >> >Lokesh. >> > >> > >> > >> > >> >On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV < >> noufal at nibrahim.net.in> wrote: >> > >> >On Fri, Mar 21 2014, lokesh bobby wrote: >> > >> > >> >> Hi ALL, >> >> >> >> Can you share your thoughts on how to parse a JSON file by using >> >> python? >> > >> >import json >> > >> >with open("data.json") as f: >> > json.load(f) >> > >> > >> >[...] >> > >> > >> >-- >> >Cordially, >> >Noufal >> >http://nibrahim.net.in >> >_______________________________________________ >> >BangPypers mailing list >> >BangPypers at python.org >> >https://mail.python.org/mailman/listinfo/bangpypers >> > >> _______________________________________________ >> BangPypers mailing list >> BangPypers at python.org >> https://mail.python.org/mailman/listinfo/bangpypers >> > > > > -- > Prashant Gaur > > Mobile : +91 9717353657 > http://gaurprashant.blogspot.in/ > http://stackoverflow.com/users/1850358/prashant-gaur > http://www.about.me/prashantgaur/ > > From lokeshbobbys at yahoo.com Fri Mar 21 10:52:28 2014 From: lokeshbobbys at yahoo.com (lokesh bobby) Date: Fri, 21 Mar 2014 17:52:28 +0800 (SGT) Subject: [BangPypers] JSON PARSER In-Reply-To: References: <1395389920.23044.YahooMailNeo@web193806.mail.sg3.yahoo.com> <878us4c5fg.fsf@sanitarium.localdomain> <1395392403.5407.YahooMailNeo@web193803.mail.sg3.yahoo.com> <1395394151.2035.YahooMailNeo@web193801.mail.sg3.yahoo.com> Message-ID: <1395395548.10193.YahooMailNeo@web193805.mail.sg3.yahoo.com> Hi Jayanth/Prashant, Either "the duplicates to be loaded" or "An ouput of all the duplicate key names in a JSON file" should be fine for me :-) NOTE: JSON file consits of more than 2 lakhs LOC Lokesh On Friday, 21 March 2014 3:17 PM, Jayanth Koushik wrote: Hi Prashant I think he wants the duplicates to be loaded, not cause an exception. Jayanth On Fri, Mar 21, 2014 at 3:15 PM, Prashant Gaur <91prashantgaur at gmail.com> wrote: Hi Lokesh, > > >we can pass lookup while parsing your json file which will make sure that name is repetitive or not . > > >import json > > >def duplicate_checking_hook(pairs): > >??? ''' lookup for duplicate names''' > >??? result = dict() > >??? for key, val in pairs: > >??????? if key in result: > >??????????? raise KeyError('Duplicate Key specified: %s % key) > >??????? result[key] = val > >? ? return result > >>>> json.loads('''{"test":"hi","test":"bye"}''', object_pairs_hook=duplicate_checking_hook) >Traceback (most recent call last): >? File "", line 1, in >? File "/usr/lib/python2.7/json/__init__.py", line 339, in loads >??? return cls(encoding=encoding, **kw).decode(s) >? File "/usr/lib/python2.7/json/decoder.py", line 366, in decode >??? obj, end = self.raw_decode(s, idx=_w(s, 0).end()) >? File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode >??? obj, end = self.scan_once(s, idx) >? File "", line 5, in duplicate_checking_hook >KeyError: u'Duplicate key specified: a' > > >While > >>>> json.loads('''{"test":"hi","test1":"bye"}''', object_pairs_hook=duplicate_checking_hook) >{u'test': u'hi', u'test1': u'bye'} >>>> > > >? > > >defdupe_checking_hook(pairs):result =dict()forkey,val inpairs:ifkey inresult:raiseKeyError("Duplicate key specified: %s"%key)result[key]=val returnresult > > > > > > >On Fri, Mar 21, 2014 at 2:59 PM, lokesh bobby wrote: > >Hi Jayanth, >> >>Ideally speaking a JSON shouldn't be created with repetitive key names. But manually it is possible that a proper JSON file can be appended with a duplicate key. We need to catch that duplicate key. If we are going to use json.load(), the repetitive keys of the JSON file wont get loaded. Only the last occurrence of the key will be there in that loaded data. >> >>Instead I want that entire data in JSON file should be loaded. Hoping that you got the point what I want :-) >> >>Thanks, >>Lokesh. >> >> >> >> >> >> >>On Friday, 21 March 2014 2:45 PM, Jayanth Koushik wrote: >> >>Hi Lokesh >> >> >>The 'problem' that you talk about isn't really a problem. Since the JSON specification does not say what is to be done for repeated names, it is up to the implementation to decide. What is your requirement for handling repeated names? >> >> >>Jayanth >> >> >> >> >>On Fri, Mar 21, 2014 at 2:30 PM, lokesh bobby wrote: >> >>Hi Noufal, >>> >>>Thanks for your reply. I am not looking for loading the JSON file. There is a limitation in it. Go thru the links >>> >>>http://docs.python.org/2/library/json.html#repeated-names-within-an-object >>>http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object >>> >>>In order to get rid of that problem, I am looking for some JSON stream parsers. >>> >>>Thanks, >>>Lokesh. >>> >>> >>> >>> >>>On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV wrote: >>> >>>On Fri, Mar 21 2014, lokesh bobby wrote: >>> >>> >>>> Hi ALL, >>>> >>>> Can you share your thoughts on how to parse a JSON file by using >>>> python? >>> >>>import json >>> >>>with open("data.json") as f: >>>? ? ?json.load(f) >>> >>> >>>[...] >>> >>> >>>-- >>>Cordially, >>>Noufal >>>http://nibrahim.net.in >>>_______________________________________________ >>>BangPypers mailing list >>>BangPypers at python.org >>>https://mail.python.org/mailman/listinfo/bangpypers >>> >>_______________________________________________ >>BangPypers mailing list >>BangPypers at python.org >>https://mail.python.org/mailman/listinfo/bangpypers >> > > > >-- > >Prashant Gaur > >Mobile : +91 9717353657 >http://gaurprashant.blogspot.in/ >http://stackoverflow.com/users/1850358/prashant-gaur >http://www.about.me/prashantgaur/ > > From rajiv.m1991 at gmail.com Fri Mar 21 10:56:37 2014 From: rajiv.m1991 at gmail.com (Rajiv Subramanian M) Date: Fri, 21 Mar 2014 15:26:37 +0530 Subject: [BangPypers] JSON PARSER (Rajiv) Message-ID: why not use 'eval' keyword for parsing json.. Here is an example. *with 'eval' * json_data =''' { "firstName": "John", "lastName" : "Smith", "age" : 25, "address" : { "streetAddress": "21 2nd Street", "city" : "New York", "state" : "NY", "postalCode" : "10021" }, "phoneNumber": [ { "type" : "home", "number": "212 555-1234" }, { "type" : "fax", "number": "646 555-4567" } ] }''' d = eval('('+json_data+')') for key in d: print(key, ':', d[key].__class__, d[key]) *Output:* lastName : Smith age : 25 phoneNumber : [{'type': 'home', 'number': '212 555-1234'}, {'type': 'fax', 'number': '646 555-4567'}] firstName : John address : {'postalCode': '10021', 'city': 'New York', 'streetAddress': '21 2nd Street', 'state': 'NY'} On Fri, Mar 21, 2014 at 2:45 PM, wrote: > Send BangPypers mailing list submissions to > bangpypers at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/bangpypers > or, via email, send a message with subject or body 'help' to > bangpypers-request at python.org > > You can reach the person managing the list at > bangpypers-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of BangPypers digest..." > > > Today's Topics: > > 1. JSON PARSER (lokesh bobby) > 2. Re: JSON PARSER (Noufal Ibrahim KV) > 3. Re: JSON PARSER (Prashant Gaur) > 4. Re: JSON PARSER (Vishal) > 5. Re: JSON PARSER (lokesh bobby) > 6. Re: JSON PARSER (Jayanth Koushik) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Fri, 21 Mar 2014 16:18:40 +0800 (SGT) > From: lokesh bobby > To: Bangalore Python Users Group - India > Subject: [BangPypers] JSON PARSER > Message-ID: > <1395389920.23044.YahooMailNeo at web193806.mail.sg3.yahoo.com> > Content-Type: text/plain; charset=utf-8 > > Hi ALL, > > Can you share your thoughts on how to parse a JSON file by using python? > > Thanks, > Lokesh. > > ------------------------------ > > Message: 2 > Date: Fri, 21 Mar 2014 14:08:27 +0530 > From: Noufal Ibrahim KV > To: lokesh bobby > Cc: Bangalore Python Users Group - India > Subject: Re: [BangPypers] JSON PARSER > Message-ID: <878us4c5fg.fsf at sanitarium.localdomain> > Content-Type: text/plain > > On Fri, Mar 21 2014, lokesh bobby wrote: > > > Hi ALL, > > > > Can you share your thoughts on how to parse a JSON file by using > > python? > > import json > > with open("data.json") as f: > json.load(f) > > > [...] > > > -- > Cordially, > Noufal > http://nibrahim.net.in > > > ------------------------------ > > Message: 3 > Date: Fri, 21 Mar 2014 14:30:19 +0530 > From: Prashant Gaur <91prashantgaur at gmail.com> > To: Bangalore Python Users Group - India > Subject: Re: [BangPypers] JSON PARSER > Message-ID: > < > CABewc72XDpEESfCvSCXzq5GPUfer1q9z2RMYp8veEfDftmpuBA at mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > > Python provides json module to parse JSON files. > > import json > from pprint import pprint > with open('data.json') as json_file: > data = json.load(json_file) > pprint(data) > > Here i am using pprint to print result data (You can have a look > http://docs.python.org/2/library/pprint.html ) > Or > You can also use simplejson library to do same . ( > http://simplejson.readthedocs.org/en/latest/ ) > > > > > On Fri, Mar 21, 2014 at 2:08 PM, Noufal Ibrahim KV > wrote: > > > On Fri, Mar 21 2014, lokesh bobby wrote: > > > > > Hi ALL, > > > > > > Can you share your thoughts on how to parse a JSON file by using > > > python? > > > > import json > > > > with open("data.json") as f: > > json.load(f) > > > > > > [...] > > > > > > -- > > Cordially, > > Noufal > > http://nibrahim.net.in > > _______________________________________________ > > BangPypers mailing list > > BangPypers at python.org > > https://mail.python.org/mailman/listinfo/bangpypers > > > > > > -- > Prashant Gaur > > Mobile : +91 9717353657 > http://gaurprashant.blogspot.in/ > http://stackoverflow.com/users/1850358/prashant-gaur > http://www.about.me/prashantgaur/ > > > ------------------------------ > > Message: 4 > Date: Fri, 21 Mar 2014 14:31:38 +0530 > From: Vishal > To: Bangalore Python Users Group - India > Subject: Re: [BangPypers] JSON PARSER > Message-ID: > < > CACPguY8LrLjgKHytdr+2X7zHenDcYp15e1i7xFvA-FA+pSCJNQ at mail.gmail.com> > Content-Type: text/plain; charset=UTF-8 > > Hi, > I have used simplejson and ultrajson. Found ultrajson to be the fastest > amongst known libraries for Python > > UltraJSON ( > http://pushingtheweb.com/2011/03/ultra-fast-json-encoding-decoding-python/ > ) > > Compare performance: http://stackoverflow.com/a/15440843 > > Download it from here: https://pypi.python.org/pypi/ujson/ > > Take care, > Vishal > > > > > Thanks and best regards, > Vishal Sapre > > --- > "Life is 10% how you make it, and 90% how you take it" > "????? ?????, ????? ????? (Benefit for most people, Happiness for most > people.)" > --- > Please DONT print this email, unless you really need to. Save Energy & > Paper. Save the Earth. > > > On Fri, Mar 21, 2014 at 2:08 PM, Noufal Ibrahim KV > wrote: > > > On Fri, Mar 21 2014, lokesh bobby wrote: > > > > > Hi ALL, > > > > > > Can you share your thoughts on how to parse a JSON file by using > > > python? > > > > import json > > > > with open("data.json") as f: > > json.load(f) > > > > > > [...] > > > > > > -- > > Cordially, > > Noufal > > http://nibrahim.net.in > > _______________________________________________ > > BangPypers mailing list > > BangPypers at python.org > > https://mail.python.org/mailman/listinfo/bangpypers > > > > > ------------------------------ > > Message: 5 > Date: Fri, 21 Mar 2014 17:00:03 +0800 (SGT) > From: lokesh bobby > To: Noufal Ibrahim KV > Cc: Bangalore Python Users Group - India > Subject: Re: [BangPypers] JSON PARSER > Message-ID: > <1395392403.5407.YahooMailNeo at web193803.mail.sg3.yahoo.com> > Content-Type: text/plain; charset=iso-8859-1 > > Hi Noufal, > > Thanks for your reply. I am not looking for loading the JSON file. There > is a limitation in it. Go thru the links > > http://docs.python.org/2/library/json.html#repeated-names-within-an-object > > http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object > > In order to get rid of that problem, I am looking for some JSON stream > parsers. > > Thanks, > Lokesh. > > > > On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV < > noufal at nibrahim.net.in> wrote: > > On Fri, Mar 21 2014, lokesh bobby wrote: > > > > Hi ALL, > > > > Can you share your thoughts on how to parse a JSON file by using > > python? > > import json > > with open("data.json") as f: > ? ? json.load(f) > > > [...] > > > -- > Cordially, > Noufal > http://nibrahim.net.in > > ------------------------------ > > Message: 6 > Date: Fri, 21 Mar 2014 14:45:19 +0530 > From: Jayanth Koushik > To: lokesh bobby , Bangalore Python Users > Group - India > Subject: Re: [BangPypers] JSON PARSER > Message-ID: > < > CA+pEiEJF+VhmxvCh5Ef6oPVc5MBavxZ5wEoDnz2hugQ_-NtTqA at mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > > Hi Lokesh > > The 'problem' that you talk about isn't really a problem. Since the JSON > specification does not say what is to be done for repeated names, it is up > to the implementation to decide. What is your requirement for handling > repeated names? > > Jayanth > > > On Fri, Mar 21, 2014 at 2:30 PM, lokesh bobby >wrote: > > > Hi Noufal, > > > > Thanks for your reply. I am not looking for loading the JSON file. There > > is a limitation in it. Go thru the links > > > > > http://docs.python.org/2/library/json.html#repeated-names-within-an-object > > > > > http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object > > > > In order to get rid of that problem, I am looking for some JSON stream > > parsers. > > > > Thanks, > > Lokesh. > > > > > > > > On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV < > > noufal at nibrahim.net.in> wrote: > > > > On Fri, Mar 21 2014, lokesh bobby wrote: > > > > > > > Hi ALL, > > > > > > Can you share your thoughts on how to parse a JSON file by using > > > python? > > > > import json > > > > with open("data.json") as f: > > json.load(f) > > > > > > [...] > > > > > > -- > > Cordially, > > Noufal > > http://nibrahim.net.in > > _______________________________________________ > > BangPypers mailing list > > BangPypers at python.org > > https://mail.python.org/mailman/listinfo/bangpypers > > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers > > > ------------------------------ > > End of BangPypers Digest, Vol 79, Issue 8 > ***************************************** > -- Rajiv M Software Engineer. *DoubleSpring Media (P) Ltd.* #15/1 Robertson Road, Frazer Town, Bangalore 05, IND. Office: +91-80-40917126, Mobile: +91 7411 129611, Skype: rajiv.m1991, Web: www.doublespring.com. From jnkoushik at gmail.com Fri Mar 21 11:02:13 2014 From: jnkoushik at gmail.com (Jayanth Koushik) Date: Fri, 21 Mar 2014 15:32:13 +0530 Subject: [BangPypers] JSON PARSER (Rajiv) In-Reply-To: References: Message-ID: Sorry, I meant: >>> eval("{'a': 1, 'a': 2}") {'a': 2} On Fri, Mar 21, 2014 at 3:31 PM, Jayanth Koushik wrote: > Hi Rajiv > > eval does not work with duplicates. > > >>> eval("{'a': 1, 'b': 2}") > {'a': 1} > > > On Fri, Mar 21, 2014 at 3:26 PM, Rajiv Subramanian M < > rajiv.m1991 at gmail.com> wrote: > >> why not use 'eval' keyword for parsing json.. >> >> Here is an example. >> >> *with 'eval' * >> >> json_data =''' >> { >> "firstName": "John", >> "lastName" : "Smith", >> "age" : 25, >> "address" : >> { >> "streetAddress": "21 2nd Street", >> "city" : "New York", >> "state" : "NY", >> "postalCode" : "10021" >> }, >> "phoneNumber": >> [ >> { >> "type" : "home", >> "number": "212 555-1234" >> }, >> { >> "type" : "fax", >> "number": "646 555-4567" >> } >> ] >> }''' >> d = eval('('+json_data+')') >> for key in d: >> print(key, ':', d[key].__class__, d[key]) >> >> *Output:* >> >> lastName : Smith >> age : 25 >> phoneNumber : [{'type': 'home', 'number': '212 >> 555-1234'}, {'type': 'fax', 'number': '646 555-4567'}] >> firstName : John >> address : {'postalCode': '10021', 'city': 'New York', >> 'streetAddress': '21 2nd Street', 'state': 'NY'} >> >> >> >> >> On Fri, Mar 21, 2014 at 2:45 PM, wrote: >> >> > Send BangPypers mailing list submissions to >> > bangpypers at python.org >> > >> > To subscribe or unsubscribe via the World Wide Web, visit >> > https://mail.python.org/mailman/listinfo/bangpypers >> > or, via email, send a message with subject or body 'help' to >> > bangpypers-request at python.org >> > >> > You can reach the person managing the list at >> > bangpypers-owner at python.org >> > >> > When replying, please edit your Subject line so it is more specific >> > than "Re: Contents of BangPypers digest..." >> > >> > >> > Today's Topics: >> > >> > 1. JSON PARSER (lokesh bobby) >> > 2. Re: JSON PARSER (Noufal Ibrahim KV) >> > 3. Re: JSON PARSER (Prashant Gaur) >> > 4. Re: JSON PARSER (Vishal) >> > 5. Re: JSON PARSER (lokesh bobby) >> > 6. Re: JSON PARSER (Jayanth Koushik) >> > >> > >> > ---------------------------------------------------------------------- >> > >> > Message: 1 >> > Date: Fri, 21 Mar 2014 16:18:40 +0800 (SGT) >> > From: lokesh bobby >> > To: Bangalore Python Users Group - India >> > Subject: [BangPypers] JSON PARSER >> > Message-ID: >> > <1395389920.23044.YahooMailNeo at web193806.mail.sg3.yahoo.com> >> > Content-Type: text/plain; charset=utf-8 >> > >> > Hi ALL, >> > >> > Can you share your thoughts on how to parse a JSON file by using python? >> > >> > Thanks, >> > Lokesh. >> > >> > ------------------------------ >> > >> > Message: 2 >> > Date: Fri, 21 Mar 2014 14:08:27 +0530 >> > From: Noufal Ibrahim KV >> > To: lokesh bobby >> > Cc: Bangalore Python Users Group - India >> > Subject: Re: [BangPypers] JSON PARSER >> > Message-ID: <878us4c5fg.fsf at sanitarium.localdomain> >> > Content-Type: text/plain >> > >> > On Fri, Mar 21 2014, lokesh bobby wrote: >> > >> > > Hi ALL, >> > > >> > > Can you share your thoughts on how to parse a JSON file by using >> > > python? >> > >> > import json >> > >> > with open("data.json") as f: >> > json.load(f) >> > >> > >> > [...] >> > >> > >> > -- >> > Cordially, >> > Noufal >> > http://nibrahim.net.in >> > >> > >> > ------------------------------ >> > >> > Message: 3 >> > Date: Fri, 21 Mar 2014 14:30:19 +0530 >> > From: Prashant Gaur <91prashantgaur at gmail.com> >> > To: Bangalore Python Users Group - India >> > Subject: Re: [BangPypers] JSON PARSER >> > Message-ID: >> > < >> > CABewc72XDpEESfCvSCXzq5GPUfer1q9z2RMYp8veEfDftmpuBA at mail.gmail.com> >> > Content-Type: text/plain; charset=ISO-8859-1 >> > >> > Python provides json module to parse JSON files. >> > >> > import json >> > from pprint import pprint >> > with open('data.json') as json_file: >> > data = json.load(json_file) >> > pprint(data) >> > >> > Here i am using pprint to print result data (You can have a look >> > http://docs.python.org/2/library/pprint.html ) >> > Or >> > You can also use simplejson library to do same . ( >> > http://simplejson.readthedocs.org/en/latest/ ) >> > >> > >> > >> > >> > On Fri, Mar 21, 2014 at 2:08 PM, Noufal Ibrahim KV >> > wrote: >> > >> > > On Fri, Mar 21 2014, lokesh bobby wrote: >> > > >> > > > Hi ALL, >> > > > >> > > > Can you share your thoughts on how to parse a JSON file by using >> > > > python? >> > > >> > > import json >> > > >> > > with open("data.json") as f: >> > > json.load(f) >> > > >> > > >> > > [...] >> > > >> > > >> > > -- >> > > Cordially, >> > > Noufal >> > > http://nibrahim.net.in >> > > _______________________________________________ >> > > BangPypers mailing list >> > > BangPypers at python.org >> > > https://mail.python.org/mailman/listinfo/bangpypers >> > > >> > >> > >> > >> > -- >> > Prashant Gaur >> > >> > Mobile : +91 9717353657 >> > http://gaurprashant.blogspot.in/ >> > http://stackoverflow.com/users/1850358/prashant-gaur >> > http://www.about.me/prashantgaur/ >> > >> > >> > ------------------------------ >> > >> > Message: 4 >> > Date: Fri, 21 Mar 2014 14:31:38 +0530 >> > From: Vishal >> > To: Bangalore Python Users Group - India >> > Subject: Re: [BangPypers] JSON PARSER >> > Message-ID: >> > < >> > CACPguY8LrLjgKHytdr+2X7zHenDcYp15e1i7xFvA-FA+pSCJNQ at mail.gmail.com> >> > Content-Type: text/plain; charset=UTF-8 >> > >> > Hi, >> > I have used simplejson and ultrajson. Found ultrajson to be the fastest >> > amongst known libraries for Python >> > >> > UltraJSON ( >> > >> http://pushingtheweb.com/2011/03/ultra-fast-json-encoding-decoding-python/ >> > ) >> > >> > Compare performance: http://stackoverflow.com/a/15440843 >> > >> > Download it from here: https://pypi.python.org/pypi/ujson/ >> > >> > Take care, >> > Vishal >> > >> > >> > >> > >> > Thanks and best regards, >> > Vishal Sapre >> > >> > --- >> > "Life is 10% how you make it, and 90% how you take it" >> > "????? ?????, ????? ????? (Benefit for most people, Happiness for most >> > people.)" >> > --- >> > Please DONT print this email, unless you really need to. Save Energy & >> > Paper. Save the Earth. >> > >> > >> > On Fri, Mar 21, 2014 at 2:08 PM, Noufal Ibrahim KV >> > wrote: >> > >> > > On Fri, Mar 21 2014, lokesh bobby wrote: >> > > >> > > > Hi ALL, >> > > > >> > > > Can you share your thoughts on how to parse a JSON file by using >> > > > python? >> > > >> > > import json >> > > >> > > with open("data.json") as f: >> > > json.load(f) >> > > >> > > >> > > [...] >> > > >> > > >> > > -- >> > > Cordially, >> > > Noufal >> > > http://nibrahim.net.in >> > > _______________________________________________ >> > > BangPypers mailing list >> > > BangPypers at python.org >> > > https://mail.python.org/mailman/listinfo/bangpypers >> > > >> > >> > >> > ------------------------------ >> > >> > Message: 5 >> > Date: Fri, 21 Mar 2014 17:00:03 +0800 (SGT) >> > From: lokesh bobby >> > To: Noufal Ibrahim KV >> > Cc: Bangalore Python Users Group - India >> > Subject: Re: [BangPypers] JSON PARSER >> > Message-ID: >> > <1395392403.5407.YahooMailNeo at web193803.mail.sg3.yahoo.com> >> > Content-Type: text/plain; charset=iso-8859-1 >> > >> > Hi Noufal, >> > >> > Thanks for your reply. I am not looking for loading the JSON file. There >> > is a limitation in it. Go thru the links >> > >> > >> http://docs.python.org/2/library/json.html#repeated-names-within-an-object >> > >> > >> http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object >> > >> > In order to get rid of that problem, I am looking for some JSON stream >> > parsers. >> > >> > Thanks, >> > Lokesh. >> > >> > >> > >> > On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV < >> > noufal at nibrahim.net.in> wrote: >> > >> > On Fri, Mar 21 2014, lokesh bobby wrote: >> > >> > >> > > Hi ALL, >> > > >> > > Can you share your thoughts on how to parse a JSON file by using >> > > python? >> > >> > import json >> > >> > with open("data.json") as f: >> > ? ? json.load(f) >> > >> > >> > [...] >> > >> > >> > -- >> > Cordially, >> > Noufal >> > http://nibrahim.net.in >> > >> > ------------------------------ >> > >> > Message: 6 >> > Date: Fri, 21 Mar 2014 14:45:19 +0530 >> > From: Jayanth Koushik >> > To: lokesh bobby , Bangalore Python Users >> > Group - India >> > Subject: Re: [BangPypers] JSON PARSER >> > Message-ID: >> > < >> > CA+pEiEJF+VhmxvCh5Ef6oPVc5MBavxZ5wEoDnz2hugQ_-NtTqA at mail.gmail.com> >> > Content-Type: text/plain; charset=ISO-8859-1 >> > >> > Hi Lokesh >> > >> > The 'problem' that you talk about isn't really a problem. Since the JSON >> > specification does not say what is to be done for repeated names, it is >> up >> > to the implementation to decide. What is your requirement for handling >> > repeated names? >> > >> > Jayanth >> > >> > >> > On Fri, Mar 21, 2014 at 2:30 PM, lokesh bobby > > >wrote: >> > >> > > Hi Noufal, >> > > >> > > Thanks for your reply. I am not looking for loading the JSON file. >> There >> > > is a limitation in it. Go thru the links >> > > >> > > >> > >> http://docs.python.org/2/library/json.html#repeated-names-within-an-object >> > > >> > > >> > >> http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object >> > > >> > > In order to get rid of that problem, I am looking for some JSON stream >> > > parsers. >> > > >> > > Thanks, >> > > Lokesh. >> > > >> > > >> > > >> > > On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV < >> > > noufal at nibrahim.net.in> wrote: >> > > >> > > On Fri, Mar 21 2014, lokesh bobby wrote: >> > > >> > > >> > > > Hi ALL, >> > > > >> > > > Can you share your thoughts on how to parse a JSON file by using >> > > > python? >> > > >> > > import json >> > > >> > > with open("data.json") as f: >> > > json.load(f) >> > > >> > > >> > > [...] >> > > >> > > >> > > -- >> > > Cordially, >> > > Noufal >> > > http://nibrahim.net.in >> > > _______________________________________________ >> > > BangPypers mailing list >> > > BangPypers at python.org >> > > https://mail.python.org/mailman/listinfo/bangpypers >> > > >> > >> > >> > ------------------------------ >> > >> > Subject: Digest Footer >> > >> > _______________________________________________ >> > BangPypers mailing list >> > BangPypers at python.org >> > https://mail.python.org/mailman/listinfo/bangpypers >> > >> > >> > ------------------------------ >> > >> > End of BangPypers Digest, Vol 79, Issue 8 >> > ***************************************** >> > >> >> >> >> -- >> Rajiv M >> Software Engineer. >> >> *DoubleSpring Media (P) Ltd.* #15/1 Robertson Road, Frazer Town, >> Bangalore 05, IND. >> Office: +91-80-40917126, Mobile: +91 7411 129611, Skype: >> rajiv.m1991, >> Web: www.doublespring.com. >> >> >> _______________________________________________ >> BangPypers mailing list >> BangPypers at python.org >> https://mail.python.org/mailman/listinfo/bangpypers >> > > From 91prashantgaur at gmail.com Fri Mar 21 11:04:13 2014 From: 91prashantgaur at gmail.com (Prashant Gaur) Date: Fri, 21 Mar 2014 15:34:13 +0530 Subject: [BangPypers] JSON PARSER In-Reply-To: <1395395548.10193.YahooMailNeo@web193805.mail.sg3.yahoo.com> References: <1395389920.23044.YahooMailNeo@web193806.mail.sg3.yahoo.com> <878us4c5fg.fsf@sanitarium.localdomain> <1395392403.5407.YahooMailNeo@web193803.mail.sg3.yahoo.com> <1395394151.2035.YahooMailNeo@web193801.mail.sg3.yahoo.com> <1395395548.10193.YahooMailNeo@web193805.mail.sg3.yahoo.com> Message-ID: Hello Lokesh , as we know json.loads return data in form of dict and dict can never have same keys . so we can do one thing and that is to return a list of all values which are having same names. import simplejson as json from collections import defaultdict def duplicate_key_lookup(ordered_pairs): """Convert duplicate keys values to lists.""" # read all values into lists d = defaultdict(list) for k, v in ordered_pairs: d[k].append(v) # unpack lists that have only 1 item for k, v in d.items(): if len(v) == 1: d[k] = v[0] return dict(d) >>> json.loads('''{"test":"hi","test":"bye", "test1": "tata"}''', object_pairs_hook=multidict) {'test': ['hi', 'bye'], 'test1': 'tata'} On Fri, Mar 21, 2014 at 3:22 PM, lokesh bobby wrote: > Hi Jayanth/Prashant, > > Either "the duplicates to be loaded" or "An ouput of all the duplicate key > names in a JSON file" should be fine for me :-) > > NOTE: JSON file consits of more than 2 lakhs LOC > > Lokesh > > > On Friday, 21 March 2014 3:17 PM, Jayanth Koushik > wrote: > Hi Prashant > > I think he wants the duplicates to be loaded, not cause an exception. > > Jayanth > > > On Fri, Mar 21, 2014 at 3:15 PM, Prashant Gaur <91prashantgaur at gmail.com>wrote: > > Hi Lokesh, > > we can pass lookup while parsing your json file which will make sure that > name is repetitive or not . > > import json > > def duplicate_checking_hook(pairs): > ''' lookup for duplicate names''' > result = dict() > for key, val in pairs: > if key in result: > raise KeyError('Duplicate Key specified: %s % key) > result[key] = val > return result > > >>> json.loads('''{"test":"hi","test":"bye"}''', > object_pairs_hook=duplicate_checking_hook) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.7/json/__init__.py", line 339, in loads > return cls(encoding=encoding, **kw).decode(s) > File "/usr/lib/python2.7/json/decoder.py", line 366, in decode > obj, end = self.raw_decode(s, idx=_w(s, 0).end()) > File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode > obj, end = self.scan_once(s, idx) > File "", line 5, in duplicate_checking_hook > KeyError: u'Duplicate key specified: a' > > While > > >>> json.loads('''{"test":"hi","test1":"bye"}''', > object_pairs_hook=duplicate_checking_hook) > {u'test': u'hi', u'test1': u'bye'} > >>> > > > > def dupe_checking_hook(pairs): > result = dict() > for key,val in pairs: > if key in result: > raise KeyError("Duplicate key specified: %s" % key) > result[key] = val > return result > > > > > > On Fri, Mar 21, 2014 at 2:59 PM, lokesh bobby wrote: > > Hi Jayanth, > > Ideally speaking a JSON shouldn't be created with repetitive key names. > But manually it is possible that a proper JSON file can be appended with a > duplicate key. We need to catch that duplicate key. If we are going to use > json.load(), the repetitive keys of the JSON file wont get loaded. Only the > last occurrence of the key will be there in that loaded data. > > Instead I want that entire data in JSON file should be loaded. Hoping that > you got the point what I want :-) > > Thanks, > Lokesh. > > > > > > On Friday, 21 March 2014 2:45 PM, Jayanth Koushik > wrote: > > Hi Lokesh > > > The 'problem' that you talk about isn't really a problem. Since the JSON > specification does not say what is to be done for repeated names, it is up > to the implementation to decide. What is your requirement for handling > repeated names? > > > Jayanth > > > > > On Fri, Mar 21, 2014 at 2:30 PM, lokesh bobby > wrote: > > Hi Noufal, > > > >Thanks for your reply. I am not looking for loading the JSON file. There > is a limitation in it. Go thru the links > > > > > http://docs.python.org/2/library/json.html#repeated-names-within-an-object > > > http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object > > > >In order to get rid of that problem, I am looking for some JSON stream > parsers. > > > >Thanks, > >Lokesh. > > > > > > > > > >On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV < > noufal at nibrahim.net.in> wrote: > > > >On Fri, Mar 21 2014, lokesh bobby wrote: > > > > > >> Hi ALL, > >> > >> Can you share your thoughts on how to parse a JSON file by using > >> python? > > > >import json > > > >with open("data.json") as f: > > json.load(f) > > > > > >[...] > > > > > >-- > >Cordially, > >Noufal > >http://nibrahim.net.in > >_______________________________________________ > >BangPypers mailing list > >BangPypers at python.org > >https://mail.python.org/mailman/listinfo/bangpypers > > > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers > > > > > -- > Prashant Gaur > > Mobile : +91 9717353657 > http://gaurprashant.blogspot.in/ > http://stackoverflow.com/users/1850358/prashant-gaur > http://www.about.me/prashantgaur/ > > > > > -- Prashant Gaur Mobile : +91 9717353657 http://gaurprashant.blogspot.in/ http://stackoverflow.com/users/1850358/prashant-gaur http://www.about.me/prashantgaur/ From jnkoushik at gmail.com Fri Mar 21 11:01:43 2014 From: jnkoushik at gmail.com (Jayanth Koushik) Date: Fri, 21 Mar 2014 15:31:43 +0530 Subject: [BangPypers] JSON PARSER (Rajiv) In-Reply-To: References: Message-ID: Hi Rajiv eval does not work with duplicates. >>> eval("{'a': 1, 'b': 2}") {'a': 1} On Fri, Mar 21, 2014 at 3:26 PM, Rajiv Subramanian M wrote: > why not use 'eval' keyword for parsing json.. > > Here is an example. > > *with 'eval' * > > json_data =''' > { > "firstName": "John", > "lastName" : "Smith", > "age" : 25, > "address" : > { > "streetAddress": "21 2nd Street", > "city" : "New York", > "state" : "NY", > "postalCode" : "10021" > }, > "phoneNumber": > [ > { > "type" : "home", > "number": "212 555-1234" > }, > { > "type" : "fax", > "number": "646 555-4567" > } > ] > }''' > d = eval('('+json_data+')') > for key in d: > print(key, ':', d[key].__class__, d[key]) > > *Output:* > > lastName : Smith > age : 25 > phoneNumber : [{'type': 'home', 'number': '212 > 555-1234'}, {'type': 'fax', 'number': '646 555-4567'}] > firstName : John > address : {'postalCode': '10021', 'city': 'New York', > 'streetAddress': '21 2nd Street', 'state': 'NY'} > > > > > On Fri, Mar 21, 2014 at 2:45 PM, wrote: > > > Send BangPypers mailing list submissions to > > bangpypers at python.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > https://mail.python.org/mailman/listinfo/bangpypers > > or, via email, send a message with subject or body 'help' to > > bangpypers-request at python.org > > > > You can reach the person managing the list at > > bangpypers-owner at python.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of BangPypers digest..." > > > > > > Today's Topics: > > > > 1. JSON PARSER (lokesh bobby) > > 2. Re: JSON PARSER (Noufal Ibrahim KV) > > 3. Re: JSON PARSER (Prashant Gaur) > > 4. Re: JSON PARSER (Vishal) > > 5. Re: JSON PARSER (lokesh bobby) > > 6. Re: JSON PARSER (Jayanth Koushik) > > > > > > ---------------------------------------------------------------------- > > > > Message: 1 > > Date: Fri, 21 Mar 2014 16:18:40 +0800 (SGT) > > From: lokesh bobby > > To: Bangalore Python Users Group - India > > Subject: [BangPypers] JSON PARSER > > Message-ID: > > <1395389920.23044.YahooMailNeo at web193806.mail.sg3.yahoo.com> > > Content-Type: text/plain; charset=utf-8 > > > > Hi ALL, > > > > Can you share your thoughts on how to parse a JSON file by using python? > > > > Thanks, > > Lokesh. > > > > ------------------------------ > > > > Message: 2 > > Date: Fri, 21 Mar 2014 14:08:27 +0530 > > From: Noufal Ibrahim KV > > To: lokesh bobby > > Cc: Bangalore Python Users Group - India > > Subject: Re: [BangPypers] JSON PARSER > > Message-ID: <878us4c5fg.fsf at sanitarium.localdomain> > > Content-Type: text/plain > > > > On Fri, Mar 21 2014, lokesh bobby wrote: > > > > > Hi ALL, > > > > > > Can you share your thoughts on how to parse a JSON file by using > > > python? > > > > import json > > > > with open("data.json") as f: > > json.load(f) > > > > > > [...] > > > > > > -- > > Cordially, > > Noufal > > http://nibrahim.net.in > > > > > > ------------------------------ > > > > Message: 3 > > Date: Fri, 21 Mar 2014 14:30:19 +0530 > > From: Prashant Gaur <91prashantgaur at gmail.com> > > To: Bangalore Python Users Group - India > > Subject: Re: [BangPypers] JSON PARSER > > Message-ID: > > < > > CABewc72XDpEESfCvSCXzq5GPUfer1q9z2RMYp8veEfDftmpuBA at mail.gmail.com> > > Content-Type: text/plain; charset=ISO-8859-1 > > > > Python provides json module to parse JSON files. > > > > import json > > from pprint import pprint > > with open('data.json') as json_file: > > data = json.load(json_file) > > pprint(data) > > > > Here i am using pprint to print result data (You can have a look > > http://docs.python.org/2/library/pprint.html ) > > Or > > You can also use simplejson library to do same . ( > > http://simplejson.readthedocs.org/en/latest/ ) > > > > > > > > > > On Fri, Mar 21, 2014 at 2:08 PM, Noufal Ibrahim KV > > wrote: > > > > > On Fri, Mar 21 2014, lokesh bobby wrote: > > > > > > > Hi ALL, > > > > > > > > Can you share your thoughts on how to parse a JSON file by using > > > > python? > > > > > > import json > > > > > > with open("data.json") as f: > > > json.load(f) > > > > > > > > > [...] > > > > > > > > > -- > > > Cordially, > > > Noufal > > > http://nibrahim.net.in > > > _______________________________________________ > > > BangPypers mailing list > > > BangPypers at python.org > > > https://mail.python.org/mailman/listinfo/bangpypers > > > > > > > > > > > -- > > Prashant Gaur > > > > Mobile : +91 9717353657 > > http://gaurprashant.blogspot.in/ > > http://stackoverflow.com/users/1850358/prashant-gaur > > http://www.about.me/prashantgaur/ > > > > > > ------------------------------ > > > > Message: 4 > > Date: Fri, 21 Mar 2014 14:31:38 +0530 > > From: Vishal > > To: Bangalore Python Users Group - India > > Subject: Re: [BangPypers] JSON PARSER > > Message-ID: > > < > > CACPguY8LrLjgKHytdr+2X7zHenDcYp15e1i7xFvA-FA+pSCJNQ at mail.gmail.com> > > Content-Type: text/plain; charset=UTF-8 > > > > Hi, > > I have used simplejson and ultrajson. Found ultrajson to be the fastest > > amongst known libraries for Python > > > > UltraJSON ( > > > http://pushingtheweb.com/2011/03/ultra-fast-json-encoding-decoding-python/ > > ) > > > > Compare performance: http://stackoverflow.com/a/15440843 > > > > Download it from here: https://pypi.python.org/pypi/ujson/ > > > > Take care, > > Vishal > > > > > > > > > > Thanks and best regards, > > Vishal Sapre > > > > --- > > "Life is 10% how you make it, and 90% how you take it" > > "????? ?????, ????? ????? (Benefit for most people, Happiness for most > > people.)" > > --- > > Please DONT print this email, unless you really need to. Save Energy & > > Paper. Save the Earth. > > > > > > On Fri, Mar 21, 2014 at 2:08 PM, Noufal Ibrahim KV > > wrote: > > > > > On Fri, Mar 21 2014, lokesh bobby wrote: > > > > > > > Hi ALL, > > > > > > > > Can you share your thoughts on how to parse a JSON file by using > > > > python? > > > > > > import json > > > > > > with open("data.json") as f: > > > json.load(f) > > > > > > > > > [...] > > > > > > > > > -- > > > Cordially, > > > Noufal > > > http://nibrahim.net.in > > > _______________________________________________ > > > BangPypers mailing list > > > BangPypers at python.org > > > https://mail.python.org/mailman/listinfo/bangpypers > > > > > > > > > ------------------------------ > > > > Message: 5 > > Date: Fri, 21 Mar 2014 17:00:03 +0800 (SGT) > > From: lokesh bobby > > To: Noufal Ibrahim KV > > Cc: Bangalore Python Users Group - India > > Subject: Re: [BangPypers] JSON PARSER > > Message-ID: > > <1395392403.5407.YahooMailNeo at web193803.mail.sg3.yahoo.com> > > Content-Type: text/plain; charset=iso-8859-1 > > > > Hi Noufal, > > > > Thanks for your reply. I am not looking for loading the JSON file. There > > is a limitation in it. Go thru the links > > > > > http://docs.python.org/2/library/json.html#repeated-names-within-an-object > > > > > http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object > > > > In order to get rid of that problem, I am looking for some JSON stream > > parsers. > > > > Thanks, > > Lokesh. > > > > > > > > On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV < > > noufal at nibrahim.net.in> wrote: > > > > On Fri, Mar 21 2014, lokesh bobby wrote: > > > > > > > Hi ALL, > > > > > > Can you share your thoughts on how to parse a JSON file by using > > > python? > > > > import json > > > > with open("data.json") as f: > > ? ? json.load(f) > > > > > > [...] > > > > > > -- > > Cordially, > > Noufal > > http://nibrahim.net.in > > > > ------------------------------ > > > > Message: 6 > > Date: Fri, 21 Mar 2014 14:45:19 +0530 > > From: Jayanth Koushik > > To: lokesh bobby , Bangalore Python Users > > Group - India > > Subject: Re: [BangPypers] JSON PARSER > > Message-ID: > > < > > CA+pEiEJF+VhmxvCh5Ef6oPVc5MBavxZ5wEoDnz2hugQ_-NtTqA at mail.gmail.com> > > Content-Type: text/plain; charset=ISO-8859-1 > > > > Hi Lokesh > > > > The 'problem' that you talk about isn't really a problem. Since the JSON > > specification does not say what is to be done for repeated names, it is > up > > to the implementation to decide. What is your requirement for handling > > repeated names? > > > > Jayanth > > > > > > On Fri, Mar 21, 2014 at 2:30 PM, lokesh bobby > >wrote: > > > > > Hi Noufal, > > > > > > Thanks for your reply. I am not looking for loading the JSON file. > There > > > is a limitation in it. Go thru the links > > > > > > > > > http://docs.python.org/2/library/json.html#repeated-names-within-an-object > > > > > > > > > http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object > > > > > > In order to get rid of that problem, I am looking for some JSON stream > > > parsers. > > > > > > Thanks, > > > Lokesh. > > > > > > > > > > > > On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV < > > > noufal at nibrahim.net.in> wrote: > > > > > > On Fri, Mar 21 2014, lokesh bobby wrote: > > > > > > > > > > Hi ALL, > > > > > > > > Can you share your thoughts on how to parse a JSON file by using > > > > python? > > > > > > import json > > > > > > with open("data.json") as f: > > > json.load(f) > > > > > > > > > [...] > > > > > > > > > -- > > > Cordially, > > > Noufal > > > http://nibrahim.net.in > > > _______________________________________________ > > > BangPypers mailing list > > > BangPypers at python.org > > > https://mail.python.org/mailman/listinfo/bangpypers > > > > > > > > > ------------------------------ > > > > Subject: Digest Footer > > > > _______________________________________________ > > BangPypers mailing list > > BangPypers at python.org > > https://mail.python.org/mailman/listinfo/bangpypers > > > > > > ------------------------------ > > > > End of BangPypers Digest, Vol 79, Issue 8 > > ***************************************** > > > > > > -- > Rajiv M > Software Engineer. > > *DoubleSpring Media (P) Ltd.* #15/1 Robertson Road, Frazer Town, > Bangalore 05, IND. > Office: +91-80-40917126, Mobile: +91 7411 129611, Skype: > rajiv.m1991, > Web: www.doublespring.com. > > > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers > From 91prashantgaur at gmail.com Fri Mar 21 11:05:23 2014 From: 91prashantgaur at gmail.com (Prashant Gaur) Date: Fri, 21 Mar 2014 15:35:23 +0530 Subject: [BangPypers] JSON PARSER In-Reply-To: References: <1395389920.23044.YahooMailNeo@web193806.mail.sg3.yahoo.com> <878us4c5fg.fsf@sanitarium.localdomain> <1395392403.5407.YahooMailNeo@web193803.mail.sg3.yahoo.com> <1395394151.2035.YahooMailNeo@web193801.mail.sg3.yahoo.com> <1395395548.10193.YahooMailNeo@web193805.mail.sg3.yahoo.com> Message-ID: EDIT : import simplejson as json from collections import defaultdict def duplicate_key_lookup(ordered_pairs): """Convert duplicate keys values to lists.""" # read all values into lists d = defaultdict(list) for k, v in ordered_pairs: d[k].append(v) # unpack lists that have only 1 item for k, v in d.items(): if len(v) == 1: d[k] = v[0] return dict(d) >>> json.loads('''{"test":"hi","test":"bye", "test1": "tata"}''', object_pairs_hook=duplicate_key_lookup) {'test': ['hi', 'bye'], 'test1': 'tata'} On Fri, Mar 21, 2014 at 3:34 PM, Prashant Gaur <91prashantgaur at gmail.com>wrote: > Hello Lokesh , > > as we know json.loads return data in form of dict and dict can never have > same keys . > > so we can do one thing and that is to return a list of all values which > are having same names. > > import simplejson as json > from collections import defaultdict > > def duplicate_key_lookup(ordered_pairs): > """Convert duplicate keys values to lists.""" > # read all values into lists > d = defaultdict(list) > for k, v in ordered_pairs: > d[k].append(v) > # unpack lists that have only 1 item > for k, v in d.items(): > if len(v) == 1: > d[k] = v[0] > return dict(d) > > >>> json.loads('''{"test":"hi","test":"bye", "test1": "tata"}''', > object_pairs_hook=multidict) > {'test': ['hi', 'bye'], 'test1': 'tata'} > > > On Fri, Mar 21, 2014 at 3:22 PM, lokesh bobby wrote: > >> Hi Jayanth/Prashant, >> >> Either "the duplicates to be loaded" or "An ouput of all the duplicate >> key names in a JSON file" should be fine for me :-) >> >> NOTE: JSON file consits of more than 2 lakhs LOC >> >> Lokesh >> >> >> On Friday, 21 March 2014 3:17 PM, Jayanth Koushik >> wrote: >> Hi Prashant >> >> I think he wants the duplicates to be loaded, not cause an exception. >> >> Jayanth >> >> >> On Fri, Mar 21, 2014 at 3:15 PM, Prashant Gaur <91prashantgaur at gmail.com>wrote: >> >> Hi Lokesh, >> >> we can pass lookup while parsing your json file which will make sure that >> name is repetitive or not . >> >> import json >> >> def duplicate_checking_hook(pairs): >> ''' lookup for duplicate names''' >> result = dict() >> for key, val in pairs: >> if key in result: >> raise KeyError('Duplicate Key specified: %s % key) >> result[key] = val >> return result >> >> >>> json.loads('''{"test":"hi","test":"bye"}''', >> object_pairs_hook=duplicate_checking_hook) >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/lib/python2.7/json/__init__.py", line 339, in loads >> return cls(encoding=encoding, **kw).decode(s) >> File "/usr/lib/python2.7/json/decoder.py", line 366, in decode >> obj, end = self.raw_decode(s, idx=_w(s, 0).end()) >> File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode >> obj, end = self.scan_once(s, idx) >> File "", line 5, in duplicate_checking_hook >> KeyError: u'Duplicate key specified: a' >> >> While >> >> >>> json.loads('''{"test":"hi","test1":"bye"}''', >> object_pairs_hook=duplicate_checking_hook) >> {u'test': u'hi', u'test1': u'bye'} >> >>> >> >> >> >> def dupe_checking_hook(pairs): >> result = dict() >> for key,val in pairs: >> if key in result: >> raise KeyError("Duplicate key specified: %s" % key) >> result[key] = val >> return result >> >> >> >> >> >> On Fri, Mar 21, 2014 at 2:59 PM, lokesh bobby wrote: >> >> Hi Jayanth, >> >> Ideally speaking a JSON shouldn't be created with repetitive key names. >> But manually it is possible that a proper JSON file can be appended with a >> duplicate key. We need to catch that duplicate key. If we are going to use >> json.load(), the repetitive keys of the JSON file wont get loaded. Only the >> last occurrence of the key will be there in that loaded data. >> >> Instead I want that entire data in JSON file should be loaded. Hoping >> that you got the point what I want :-) >> >> Thanks, >> Lokesh. >> >> >> >> >> >> On Friday, 21 March 2014 2:45 PM, Jayanth Koushik >> wrote: >> >> Hi Lokesh >> >> >> The 'problem' that you talk about isn't really a problem. Since the JSON >> specification does not say what is to be done for repeated names, it is up >> to the implementation to decide. What is your requirement for handling >> repeated names? >> >> >> Jayanth >> >> >> >> >> On Fri, Mar 21, 2014 at 2:30 PM, lokesh bobby >> wrote: >> >> Hi Noufal, >> > >> >Thanks for your reply. I am not looking for loading the JSON file. There >> is a limitation in it. Go thru the links >> > >> > >> http://docs.python.org/2/library/json.html#repeated-names-within-an-object >> > >> http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object >> > >> >In order to get rid of that problem, I am looking for some JSON stream >> parsers. >> > >> >Thanks, >> >Lokesh. >> > >> > >> > >> > >> >On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV < >> noufal at nibrahim.net.in> wrote: >> > >> >On Fri, Mar 21 2014, lokesh bobby wrote: >> > >> > >> >> Hi ALL, >> >> >> >> Can you share your thoughts on how to parse a JSON file by using >> >> python? >> > >> >import json >> > >> >with open("data.json") as f: >> > json.load(f) >> > >> > >> >[...] >> > >> > >> >-- >> >Cordially, >> >Noufal >> >http://nibrahim.net.in >> >_______________________________________________ >> >BangPypers mailing list >> >BangPypers at python.org >> >https://mail.python.org/mailman/listinfo/bangpypers >> > >> _______________________________________________ >> BangPypers mailing list >> BangPypers at python.org >> https://mail.python.org/mailman/listinfo/bangpypers >> >> >> >> >> -- >> Prashant Gaur >> >> Mobile : +91 9717353657 >> http://gaurprashant.blogspot.in/ >> http://stackoverflow.com/users/1850358/prashant-gaur >> http://www.about.me/prashantgaur/ >> >> >> >> >> > > > -- > Prashant Gaur > > Mobile : +91 9717353657 > http://gaurprashant.blogspot.in/ > http://stackoverflow.com/users/1850358/prashant-gaur > http://www.about.me/prashantgaur/ > > -- Prashant Gaur Mobile : +91 9717353657 http://gaurprashant.blogspot.in/ http://stackoverflow.com/users/1850358/prashant-gaur http://www.about.me/prashantgaur/ From lokeshbobbys at yahoo.com Fri Mar 21 11:41:30 2014 From: lokeshbobbys at yahoo.com (lokesh bobby) Date: Fri, 21 Mar 2014 18:41:30 +0800 (SGT) Subject: [BangPypers] JSON PARSER In-Reply-To: References: <1395389920.23044.YahooMailNeo@web193806.mail.sg3.yahoo.com> <878us4c5fg.fsf@sanitarium.localdomain> <1395392403.5407.YahooMailNeo@web193803.mail.sg3.yahoo.com> <1395394151.2035.YahooMailNeo@web193801.mail.sg3.yahoo.com> <1395395548.10193.YahooMailNeo@web193805.mail.sg3.yahoo.com> Message-ID: <1395398490.10262.YahooMailNeo@web193805.mail.sg3.yahoo.com> Hi Prashant, I have 2 concerns here 1. As I mentioned earlier, my file consists of more than 2 lac lines. So it is not possible to load that many number of lines inside json.loads(). We need to pass the file, which itself is a limitation as explained earlier. 2. It is not an ideal solution for me - creating a list of the values of duplicate keys, because my values are not just single word strings. They are again big dicts. Thanks, Lokesh On Friday, 21 March 2014 3:35 PM, Prashant Gaur <91prashantgaur at gmail.com> wrote: EDIT? : import simplejson as json from collections import defaultdict def duplicate_key_lookup(ordered_pairs): ???? """Convert duplicate keys values to lists.""" ???? # read all values into lists ???? d = defaultdict(list) ???? for k, v in ordered_pairs: ???????? d[k].append(v) ???? # unpack lists that have only 1 item ???? for k, v in d.items(): ???????? if len(v) == 1: ???????????? d[k] = v[0] ????? return dict(d) >>> json.loads('''{"test":"hi","test":"bye", "test1": "tata"}''', object_pairs_hook=duplicate_key_lookup) {'test': ['hi', 'bye'], 'test1': 'tata'} On Fri, Mar 21, 2014 at 3:34 PM, Prashant Gaur <91prashantgaur at gmail.com> wrote: Hello Lokesh , > > >as we know json.loads return data in form of dict and dict can never have same keys . > > >so we can do one thing and that is to return a list of all values which are having same names. > >import simplejson as json >from collections import defaultdict > >def duplicate_key_lookup(ordered_pairs): >??? """Convert duplicate keys values to lists.""" >??? # read all values into lists >???? d = defaultdict(list) >???? for k, v in ordered_pairs: >???????? d[k].append(v) >???????? # unpack lists that have only 1 item >???? for k, v in d.items(): >???????? if len(v) == 1: >???????????? d[k] = v[0] >????? return dict(d) > >>>> json.loads('''{"test":"hi","test":"bye", "test1": "tata"}''', object_pairs_hook=multidict) >{'test': ['hi', 'bye'], 'test1': 'tata'} > > > > >On Fri, Mar 21, 2014 at 3:22 PM, lokesh bobby wrote: > >Hi Jayanth/Prashant, >> >> >>Either "the duplicates to be loaded" or "An ouput of all the duplicate key names in a JSON file" should be fine for me :-) >> >> >>NOTE: JSON file consits of more than 2 lakhs LOC >> >> >>Lokesh >> >> >> >>On Friday, 21 March 2014 3:17 PM, Jayanth Koushik wrote: >> >>Hi Prashant >> >>I think he wants the duplicates to be loaded, not cause an exception. >> >>Jayanth >> >> >> >> >>On Fri, Mar 21, 2014 at 3:15 PM, Prashant Gaur <91prashantgaur at gmail.com> wrote: >> >>Hi Lokesh, >>> >>> >>>we can pass lookup while parsing your json file which will make sure that name is repetitive or not . >>> >>> >>>import json >>> >>> >>>def duplicate_checking_hook(pairs): >>> >>>??? ''' lookup for duplicate names''' >>> >>>??? result = dict() >>> >>>??? for key, val in pairs: >>> >>>??????? if key in result: >>> >>>??????????? raise KeyError('Duplicate Key specified: %s % key) >>> >>>??????? result[key] = val >>> >>>? ? return result >>> >>>>>> json.loads('''{"test":"hi","test":"bye"}''', object_pairs_hook=duplicate_checking_hook) >>>Traceback (most recent call last): >>>? File "", line 1, in >>>? File "/usr/lib/python2.7/json/__init__.py", line 339, in loads >>>??? return cls(encoding=encoding, **kw).decode(s) >>>? File "/usr/lib/python2.7/json/decoder.py", line 366, in decode >>>??? obj, end = self.raw_decode(s, idx=_w(s, 0).end()) >>>? File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode >>>??? obj, end = self.scan_once(s, idx) >>>? File "", line 5, in duplicate_checking_hook >>>KeyError: u'Duplicate key specified: a' >>> >>> >>>While >>> >>>>>> json.loads('''{"test":"hi","test1":"bye"}''', object_pairs_hook=duplicate_checking_hook) >>>{u'test': u'hi', u'test1': u'bye'} >>>>>> >>> >>> >>>? >>> >>> >>>defdupe_checking_hook(pairs):result =dict()forkey,val inpairs:ifkey inresult:raiseKeyError("Duplicate key specified: %s"%key)result[key]=val returnresult >>> >>> >>> >>> >>> >>> >>>On Fri, Mar 21, 2014 at 2:59 PM, lokesh bobby wrote: >>> >>>Hi Jayanth, >>>> >>>>Ideally speaking a JSON shouldn't be created with repetitive key names. But manually it is possible that a proper JSON file can be appended with a duplicate key. We need to catch that duplicate key. If we are going to use json.load(), the repetitive keys of the JSON file wont get loaded. Only the last occurrence of the key will be there in that loaded data. >>>> >>>>Instead I want that entire data in JSON file should be loaded. Hoping that you got the point what I want :-) >>>> >>>>Thanks, >>>>Lokesh. >>>> >>>> >>>> >>>> >>>> >>>> >>>>On Friday, 21 March 2014 2:45 PM, Jayanth Koushik wrote: >>>> >>>>Hi Lokesh >>>> >>>> >>>>The 'problem' that you talk about isn't really a problem. Since the JSON specification does not say what is to be done for repeated names, it is up to the implementation to decide. What is your requirement for handling repeated names? >>>> >>>> >>>>Jayanth >>>> >>>> >>>> >>>> >>>>On Fri, Mar 21, 2014 at 2:30 PM, lokesh bobby wrote: >>>> >>>>Hi Noufal, >>>>> >>>>>Thanks for your reply. I am not looking for loading the JSON file. There is a limitation in it. Go thru the links >>>>> >>>>>http://docs.python.org/2/library/json.html#repeated-names-within-an-object >>>>>http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object >>>>> >>>>>In order to get rid of that problem, I am looking for some JSON stream parsers. >>>>> >>>>>Thanks, >>>>>Lokesh. >>>>> >>>>> >>>>> >>>>> >>>>>On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV wrote: >>>>> >>>>>On Fri, Mar 21 2014, lokesh bobby wrote: >>>>> >>>>> >>>>>> Hi ALL, >>>>>> >>>>>> Can you share your thoughts on how to parse a JSON file by using >>>>>> python? >>>>> >>>>>import json >>>>> >>>>>with open("data.json") as f: >>>>>? ? ?json.load(f) >>>>> >>>>> >>>>>[...] >>>>> >>>>> >>>>>-- >>>>>Cordially, >>>>>Noufal >>>>>http://nibrahim.net.in >>>>>_______________________________________________ >>>>>BangPypers mailing list >>>>>BangPypers at python.org >>>>>https://mail.python.org/mailman/listinfo/bangpypers >>>>> >>>>_______________________________________________ >>>>BangPypers mailing list >>>>BangPypers at python.org >>>>https://mail.python.org/mailman/listinfo/bangpypers >>>> >>> >>> >>> >>>-- >>> >>>Prashant Gaur >>> >>>Mobile : +91 9717353657 >>>http://gaurprashant.blogspot.in/ >>>http://stackoverflow.com/users/1850358/prashant-gaur >>>http://www.about.me/prashantgaur/ >>> >>> >> >> >> > > >-- > >Prashant Gaur > >Mobile : +91 9717353657 >http://gaurprashant.blogspot.in/ >http://stackoverflow.com/users/1850358/prashant-gaur >http://www.about.me/prashantgaur/ > > -- Prashant Gaur Mobile : +91 9717353657 http://gaurprashant.blogspot.in/ http://stackoverflow.com/users/1850358/prashant-gaur http://www.about.me/prashantgaur/ From noufal at nibrahim.net.in Fri Mar 21 12:36:14 2014 From: noufal at nibrahim.net.in (Noufal Ibrahim KV) Date: Fri, 21 Mar 2014 17:06:14 +0530 Subject: [BangPypers] JSON PARSER In-Reply-To: <1395398490.10262.YahooMailNeo@web193805.mail.sg3.yahoo.com> (lokesh bobby's message of "Fri, 21 Mar 2014 18:41:30 +0800 (SGT)") References: <1395389920.23044.YahooMailNeo@web193806.mail.sg3.yahoo.com> <878us4c5fg.fsf@sanitarium.localdomain> <1395392403.5407.YahooMailNeo@web193803.mail.sg3.yahoo.com> <1395394151.2035.YahooMailNeo@web193801.mail.sg3.yahoo.com> <1395395548.10193.YahooMailNeo@web193805.mail.sg3.yahoo.com> <1395398490.10262.YahooMailNeo@web193805.mail.sg3.yahoo.com> Message-ID: <87y503bx75.fsf@sanitarium.localdomain> On Fri, Mar 21 2014, lokesh bobby wrote: > Hi Prashant, > > I have 2 concerns here > > 1. As I mentioned earlier, my file consists of more than 2 lac > lines. So it is not possible to load that many number of lines inside > json.loads(). We need to pass the file, which itself is a limitation > as explained earlier. > > 2. It is not an ideal solution for me - creating a list of the values > of duplicate keys, because my values are not just single word > strings. They are again big dicts. What exactly would you like to do? "Parse a json" is not specific enough. I understand the input data. What kind of API would you like? What should be returned from it if I give it the json file? [...] -- Cordially, Noufal http://nibrahim.net.in From rajiv.m1991 at gmail.com Fri Mar 21 13:58:15 2014 From: rajiv.m1991 at gmail.com (Rajiv Subramanian M) Date: Fri, 21 Mar 2014 18:28:15 +0530 Subject: [BangPypers] JSON PARSER (Rajiv) Message-ID: Hi Jayanth, I didn't get what you mean duplicate in json data... And the output for the following >>> eval("{'a': 1, 'b': 2}") will be {'a': 1, 'b': 2} It can't be {'a': 1} because I believe eval() takes string argument and it will throw exception only if that argument string doesn't met the valid syntax of Python.. Please provide an example json-data with duplicates.. so that I could understand On Fri, Mar 21, 2014 at 3:32 PM, wrote: > Send BangPypers mailing list submissions to > bangpypers at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/bangpypers > or, via email, send a message with subject or body 'help' to > bangpypers-request at python.org > > You can reach the person managing the list at > bangpypers-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of BangPypers digest..." > > > Today's Topics: > > 1. Re: JSON PARSER (Rajiv) (Rajiv Subramanian M) > 2. Re: JSON PARSER (Rajiv) (Jayanth Koushik) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Fri, 21 Mar 2014 15:26:37 +0530 > From: Rajiv Subramanian M > To: bangpypers at python.org > Subject: Re: [BangPypers] JSON PARSER (Rajiv) > Message-ID: > < > CAELut3XeKoUE8LBFWPyTROOMaXgNm4M_w_pQE-VAEoXd9nbhCw at mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > > > why not use 'eval' keyword for parsing json.. > > Here is an example. > > *with 'eval' * > > > json_data =''' > { > "firstName": "John", > "lastName" : "Smith", > "age" : 25, > "address" : > { > "streetAddress": "21 2nd Street", > "city" : "New York", > "state" : "NY", > "postalCode" : "10021" > }, > "phoneNumber": > [ > { > "type" : "home", > "number": "212 555-1234" > }, > { > "type" : "fax", > "number": "646 555-4567" > } > ] > }''' > d = eval('('+json_data+')') > for key in d: > print(key, ':', d[key].__class__, d[key]) > > *Output:* > > > lastName : Smith > age : 25 > phoneNumber : [{'type': 'home', 'number': '212 > 555-1234'}, {'type': 'fax', 'number': '646 555-4567'}] > firstName : John > address : {'postalCode': '10021', 'city': 'New York', > 'streetAddress': '21 2nd Street', 'state': 'NY'} > > -- > Rajiv M > Software Engineer. > > *DoubleSpring Media (P) Ltd.* #15/1 Robertson Road, Frazer Town, > > Bangalore 05, IND. > Office: +91-80-40917126, Mobile: +91 7411 129611, Skype: > rajiv.m1991, > Web: www.doublespring.com. > > > > > ------------------------------ > > Message: 2 > Date: Fri, 21 Mar 2014 15:32:13 +0530 > From: Jayanth Koushik > To: Bangalore Python Users Group - India > Subject: Re: [BangPypers] JSON PARSER (Rajiv) > Message-ID: > < > CA+pEiEKbU2L30EOiqmfK6Wh-y7jVh3Fu5JxzGsM1fCQY-tzzEQ at mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > > Sorry, I meant: > > >>> eval("{'a': 1, 'a': 2}") > {'a': 2} > > > On Fri, Mar 21, 2014 at 3:31 PM, Jayanth Koushik >wrote: > > > Hi Rajiv > > > > eval does not work with duplicates. > > > > >>> eval("{'a': 1, 'b': 2}") > > {'a': 1} From dhruvbaldawa at gmail.com Sat Mar 22 05:28:55 2014 From: dhruvbaldawa at gmail.com (Dhruv Baldawa) Date: Sat, 22 Mar 2014 09:58:55 +0530 Subject: [BangPypers] JSON PARSER (Rajiv) In-Reply-To: References: Message-ID: eval will not work always, especially when you have "null" values. In [1]: eval('{"a": null}') --------------------------------------------------------------------------- NameError Traceback (most recent call last) in () ----> 1 eval('{"a": null}') in () NameError: name 'null' is not defined On Fri, Mar 21, 2014 at 3:26 PM, Rajiv Subramanian M wrote: > why not use 'eval' keyword for parsing json.. > > Here is an example. > > *with 'eval' * > > json_data =''' > { > "firstName": "John", > "lastName" : "Smith", > "age" : 25, > "address" : > { > "streetAddress": "21 2nd Street", > "city" : "New York", > "state" : "NY", > "postalCode" : "10021" > }, > "phoneNumber": > [ > { > "type" : "home", > "number": "212 555-1234" > }, > { > "type" : "fax", > "number": "646 555-4567" > } > ] > }''' > d = eval('('+json_data+')') > for key in d: > print(key, ':', d[key].__class__, d[key]) > > *Output:* > > lastName : Smith > age : 25 > phoneNumber : [{'type': 'home', 'number': '212 > 555-1234'}, {'type': 'fax', 'number': '646 555-4567'}] > firstName : John > address : {'postalCode': '10021', 'city': 'New York', > 'streetAddress': '21 2nd Street', 'state': 'NY'} > > > > > On Fri, Mar 21, 2014 at 2:45 PM, wrote: > > > Send BangPypers mailing list submissions to > > bangpypers at python.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > https://mail.python.org/mailman/listinfo/bangpypers > > or, via email, send a message with subject or body 'help' to > > bangpypers-request at python.org > > > > You can reach the person managing the list at > > bangpypers-owner at python.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of BangPypers digest..." > > > > > > Today's Topics: > > > > 1. JSON PARSER (lokesh bobby) > > 2. Re: JSON PARSER (Noufal Ibrahim KV) > > 3. Re: JSON PARSER (Prashant Gaur) > > 4. Re: JSON PARSER (Vishal) > > 5. Re: JSON PARSER (lokesh bobby) > > 6. Re: JSON PARSER (Jayanth Koushik) > > > > > > ---------------------------------------------------------------------- > > > > Message: 1 > > Date: Fri, 21 Mar 2014 16:18:40 +0800 (SGT) > > From: lokesh bobby > > To: Bangalore Python Users Group - India > > Subject: [BangPypers] JSON PARSER > > Message-ID: > > <1395389920.23044.YahooMailNeo at web193806.mail.sg3.yahoo.com> > > Content-Type: text/plain; charset=utf-8 > > > > Hi ALL, > > > > Can you share your thoughts on how to parse a JSON file by using python? > > > > Thanks, > > Lokesh. > > > > ------------------------------ > > > > Message: 2 > > Date: Fri, 21 Mar 2014 14:08:27 +0530 > > From: Noufal Ibrahim KV > > To: lokesh bobby > > Cc: Bangalore Python Users Group - India > > Subject: Re: [BangPypers] JSON PARSER > > Message-ID: <878us4c5fg.fsf at sanitarium.localdomain> > > Content-Type: text/plain > > > > On Fri, Mar 21 2014, lokesh bobby wrote: > > > > > Hi ALL, > > > > > > Can you share your thoughts on how to parse a JSON file by using > > > python? > > > > import json > > > > with open("data.json") as f: > > json.load(f) > > > > > > [...] > > > > > > -- > > Cordially, > > Noufal > > http://nibrahim.net.in > > > > > > ------------------------------ > > > > Message: 3 > > Date: Fri, 21 Mar 2014 14:30:19 +0530 > > From: Prashant Gaur <91prashantgaur at gmail.com> > > To: Bangalore Python Users Group - India > > Subject: Re: [BangPypers] JSON PARSER > > Message-ID: > > < > > CABewc72XDpEESfCvSCXzq5GPUfer1q9z2RMYp8veEfDftmpuBA at mail.gmail.com> > > Content-Type: text/plain; charset=ISO-8859-1 > > > > Python provides json module to parse JSON files. > > > > import json > > from pprint import pprint > > with open('data.json') as json_file: > > data = json.load(json_file) > > pprint(data) > > > > Here i am using pprint to print result data (You can have a look > > http://docs.python.org/2/library/pprint.html ) > > Or > > You can also use simplejson library to do same . ( > > http://simplejson.readthedocs.org/en/latest/ ) > > > > > > > > > > On Fri, Mar 21, 2014 at 2:08 PM, Noufal Ibrahim KV > > wrote: > > > > > On Fri, Mar 21 2014, lokesh bobby wrote: > > > > > > > Hi ALL, > > > > > > > > Can you share your thoughts on how to parse a JSON file by using > > > > python? > > > > > > import json > > > > > > with open("data.json") as f: > > > json.load(f) > > > > > > > > > [...] > > > > > > > > > -- > > > Cordially, > > > Noufal > > > http://nibrahim.net.in > > > _______________________________________________ > > > BangPypers mailing list > > > BangPypers at python.org > > > https://mail.python.org/mailman/listinfo/bangpypers > > > > > > > > > > > -- > > Prashant Gaur > > > > Mobile : +91 9717353657 > > http://gaurprashant.blogspot.in/ > > http://stackoverflow.com/users/1850358/prashant-gaur > > http://www.about.me/prashantgaur/ > > > > > > ------------------------------ > > > > Message: 4 > > Date: Fri, 21 Mar 2014 14:31:38 +0530 > > From: Vishal > > To: Bangalore Python Users Group - India > > Subject: Re: [BangPypers] JSON PARSER > > Message-ID: > > < > > CACPguY8LrLjgKHytdr+2X7zHenDcYp15e1i7xFvA-FA+pSCJNQ at mail.gmail.com> > > Content-Type: text/plain; charset=UTF-8 > > > > Hi, > > I have used simplejson and ultrajson. Found ultrajson to be the fastest > > amongst known libraries for Python > > > > UltraJSON ( > > > http://pushingtheweb.com/2011/03/ultra-fast-json-encoding-decoding-python/ > > ) > > > > Compare performance: http://stackoverflow.com/a/15440843 > > > > Download it from here: https://pypi.python.org/pypi/ujson/ > > > > Take care, > > Vishal > > > > > > > > > > Thanks and best regards, > > Vishal Sapre > > > > --- > > "Life is 10% how you make it, and 90% how you take it" > > "????? ?????, ????? ????? (Benefit for most people, Happiness for most > > people.)" > > --- > > Please DONT print this email, unless you really need to. Save Energy & > > Paper. Save the Earth. > > > > > > On Fri, Mar 21, 2014 at 2:08 PM, Noufal Ibrahim KV > > wrote: > > > > > On Fri, Mar 21 2014, lokesh bobby wrote: > > > > > > > Hi ALL, > > > > > > > > Can you share your thoughts on how to parse a JSON file by using > > > > python? > > > > > > import json > > > > > > with open("data.json") as f: > > > json.load(f) > > > > > > > > > [...] > > > > > > > > > -- > > > Cordially, > > > Noufal > > > http://nibrahim.net.in > > > _______________________________________________ > > > BangPypers mailing list > > > BangPypers at python.org > > > https://mail.python.org/mailman/listinfo/bangpypers > > > > > > > > > ------------------------------ > > > > Message: 5 > > Date: Fri, 21 Mar 2014 17:00:03 +0800 (SGT) > > From: lokesh bobby > > To: Noufal Ibrahim KV > > Cc: Bangalore Python Users Group - India > > Subject: Re: [BangPypers] JSON PARSER > > Message-ID: > > <1395392403.5407.YahooMailNeo at web193803.mail.sg3.yahoo.com> > > Content-Type: text/plain; charset=iso-8859-1 > > > > Hi Noufal, > > > > Thanks for your reply. I am not looking for loading the JSON file. There > > is a limitation in it. Go thru the links > > > > > http://docs.python.org/2/library/json.html#repeated-names-within-an-object > > > > > http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object > > > > In order to get rid of that problem, I am looking for some JSON stream > > parsers. > > > > Thanks, > > Lokesh. > > > > > > > > On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV < > > noufal at nibrahim.net.in> wrote: > > > > On Fri, Mar 21 2014, lokesh bobby wrote: > > > > > > > Hi ALL, > > > > > > Can you share your thoughts on how to parse a JSON file by using > > > python? > > > > import json > > > > with open("data.json") as f: > > ? ? json.load(f) > > > > > > [...] > > > > > > -- > > Cordially, > > Noufal > > http://nibrahim.net.in > > > > ------------------------------ > > > > Message: 6 > > Date: Fri, 21 Mar 2014 14:45:19 +0530 > > From: Jayanth Koushik > > To: lokesh bobby , Bangalore Python Users > > Group - India > > Subject: Re: [BangPypers] JSON PARSER > > Message-ID: > > < > > CA+pEiEJF+VhmxvCh5Ef6oPVc5MBavxZ5wEoDnz2hugQ_-NtTqA at mail.gmail.com> > > Content-Type: text/plain; charset=ISO-8859-1 > > > > Hi Lokesh > > > > The 'problem' that you talk about isn't really a problem. Since the JSON > > specification does not say what is to be done for repeated names, it is > up > > to the implementation to decide. What is your requirement for handling > > repeated names? > > > > Jayanth > > > > > > On Fri, Mar 21, 2014 at 2:30 PM, lokesh bobby > >wrote: > > > > > Hi Noufal, > > > > > > Thanks for your reply. I am not looking for loading the JSON file. > There > > > is a limitation in it. Go thru the links > > > > > > > > > http://docs.python.org/2/library/json.html#repeated-names-within-an-object > > > > > > > > > http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object > > > > > > In order to get rid of that problem, I am looking for some JSON stream > > > parsers. > > > > > > Thanks, > > > Lokesh. > > > > > > > > > > > > On Friday, 21 March 2014 2:09 PM, Noufal Ibrahim KV < > > > noufal at nibrahim.net.in> wrote: > > > > > > On Fri, Mar 21 2014, lokesh bobby wrote: > > > > > > > > > > Hi ALL, > > > > > > > > Can you share your thoughts on how to parse a JSON file by using > > > > python? > > > > > > import json > > > > > > with open("data.json") as f: > > > json.load(f) > > > > > > > > > [...] > > > > > > > > > -- > > > Cordially, > > > Noufal > > > http://nibrahim.net.in > > > _______________________________________________ > > > BangPypers mailing list > > > BangPypers at python.org > > > https://mail.python.org/mailman/listinfo/bangpypers > > > > > > > > > ------------------------------ > > > > Subject: Digest Footer > > > > _______________________________________________ > > BangPypers mailing list > > BangPypers at python.org > > https://mail.python.org/mailman/listinfo/bangpypers > > > > > > ------------------------------ > > > > End of BangPypers Digest, Vol 79, Issue 8 > > ***************************************** > > > > > > -- > Rajiv M > Software Engineer. > > *DoubleSpring Media (P) Ltd.* #15/1 Robertson Road, Frazer Town, > Bangalore 05, IND. > Office: +91-80-40917126, Mobile: +91 7411 129611, Skype: > rajiv.m1991, > Web: www.doublespring.com. > > > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers > -- Dhruv Baldawa (http://www.dhruvb.com) From rajiv.m1991 at gmail.com Sat Mar 22 15:18:25 2014 From: rajiv.m1991 at gmail.com (Rajiv Subramanian M) Date: Sat, 22 Mar 2014 19:48:25 +0530 Subject: [BangPypers] JSON PARSER (Rajiv) In-Reply-To: References: Message-ID: Hi dhuruv, I know null cases exists. I will throw an exception "UN defined variable null". But you can solve it by declare a variable null = None Then execute the eval command. Any issues? From shrikrishna.holla at gmail.com Sun Mar 23 10:41:38 2014 From: shrikrishna.holla at gmail.com (Shrikrishna Holla) Date: Sun, 23 Mar 2014 15:11:38 +0530 Subject: [BangPypers] JSON PARSER (Rajiv) In-Reply-To: References: Message-ID: http://stackoverflow.com/questions/1083250/running-json-through-pythons-eval On Mar 22, 2014 7:48 PM, "Rajiv Subramanian M" wrote: > Hi dhuruv, > > I know null cases exists. I will throw an exception "UN defined variable > null". But you can solve it by declare a variable > > null = None > > Then execute the eval command. Any issues? > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > https://mail.python.org/mailman/listinfo/bangpypers > From nitin.nitp at gmail.com Tue Mar 25 08:00:35 2014 From: nitin.nitp at gmail.com (Nitin Kumar) Date: Tue, 25 Mar 2014 12:30:35 +0530 Subject: [BangPypers] Query with respect to mock module Message-ID: Hi All, I am try to write test case with mocking original libraries. But we have scenario that some time we need this mock but some time we need to create object of original class so that test run on real scenario. Is there a way we can play with mock library or any other way that some time same test case runs with mock and some time with original objects? Right now we are writing 2 testcases one using mock and one with original class object. Nitin K From saurabh.hirani at gmail.com Tue Mar 25 13:40:16 2014 From: saurabh.hirani at gmail.com (saurabh) Date: Tue, 25 Mar 2014 05:40:16 -0700 (PDT) Subject: [BangPypers] volunteer for conducting basic python training at CIT, Gubbi, Bangalore. Message-ID: <1395751216187-5051622.post@n6.nabble.com> Hi everyone, As a part of python week last year, I had volunteered to conduct an introductory session at CIT Gubbi for the Comp Sci batch. Post that I visited the campus again to do a introductory training for a different batch of students. The college is interested in having a 3 day session (saturdays) for students so that they can learn basic python. I will not be able to take it up this time. Wanted to broadcast if anyone is interested in taking it up. If not for a 3-day stint, a 1 or 2 day introductory session covering python basics would also suffice - but having a multi-day thing (continuous or alternate saturdays) would be better as students would get to practice and get some feedback. As the college is in Gubbi, they provide car pickup and drop in Bangalore for anyone who takes the session. If any of you are interested - could you please mail me separately at saurabh.hirani at gmail.com? Thanks. -- regards, Saurabh. -- View this message in context: http://python.6.x6.nabble.com/volunteer-for-conducting-basic-python-training-at-CIT-Gubbi-Bangalore-tp5051622.html Sent from the Bangalore (BangPypers) mailing list archive at Nabble.com. From sateeshpyper at gmail.com Tue Mar 25 15:48:59 2014 From: sateeshpyper at gmail.com (Sateesh Kumar) Date: Tue, 25 Mar 2014 20:18:59 +0530 Subject: [BangPypers] Query with respect to mock module In-Reply-To: References: Message-ID: On Tue, Mar 25, 2014 at 12:30 PM, Nitin Kumar wrote: > Hi All, > > I am try to write test case with mocking original libraries. > But we have scenario that some time we need this mock but some time we need > to create object of original class so that test run on real scenario. > > Is there a way we can play with mock library or any other way that some > time same test case runs with mock and some time with original objects? > > Right now we are writing 2 testcases one using mock and one with original > class object. > > You have not mentioned which is the mock module you are using. If you are using 'Mock'[1], one way in which you can switch between invoking real method and mock method is to use the 'patch' decoratror provided by mock module as a context manager. The below example illustrates the approach: %cat sample.py from mock import patch import unittest class Hello(object): def process(self): print 'I am real method' return 200 class Secondary(object): def __init__(self, r): self.requester = r def manage(self): return self.requester.process() class TestSecondary(unittest.TestCase): def test_manage_withmock(self): h = Hello() s = Secondary(h) with patch.object(Hello, 'process', return_value= 100) as mock_method: print s.manage() print s.manage() if __name__ == '__main__': unittest.main() %python sample.py 100 I am real method 200 The above approach is explained in the Mock quick guide [1]. 1. http://www.voidspace.org.uk/python/mock/index.html HTH, sateesh From careers at doublespring.com Wed Mar 26 18:15:20 2014 From: careers at doublespring.com (Shuhaib Shariff) Date: Wed, 26 Mar 2014 22:45:20 +0530 Subject: [BangPypers] [JOBS] Django Developers Message-ID: DoubleSpring seeks passionate PYTHON / DJANGO developers with experience in building or contributing to Open Source projects. We are constantly rolling out new products so the right individual would be able to write clean code and work in a fast pace environment. We highly value native ability, passion and the right attitude. Requirements - Technical proficiency with Python and Django. - Technical proficiency in JavaScript. - Experience with MySQL / PgSQL. - Experience with MVC design patterns and solid algorithm skills. - 1+ years of industry experience Location: Bangalore How to apply Send your resume to: careers [at] doublespring.com