Re: [Tutor] How to break long lines?
On 23/02/13 13:03, Dave Angel wrote: On 02/22/2013 08:22 PM, Jim Byrnes wrote: snip Thanks for giving me so many options to use in the future. When reading I completely blew by the single quote on a single line part. The db is sqlite3 and it seems happy with ''' strings. FWIW, there is absolutely no difference between a string object created with single quotes, one created with triple-quotes, or one created by calling some function, or by evaluating some expression. sqlite3 could not possibly tell the difference, even if it wanted. This is true. A triple-quoted string on a single line is a single line of text: s = Hello world But in general, it is fair to expect that most triple-quoted strings will contain at least one newline, and single-quoted strings generally won't. It might be that some databases dislikes receiving SQL queries containing newlines. In any case, it bears repeating that strings are strings in Python, whatever delimiters you use. The only difference between single-quoted, triple-quoted, and raw strings, is the parsing rules applied at compile-time, not the object you get at the end. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trying to avoid using eval..
Rohit Mediratta wrote: I want to reload my Module after I fix bugs and want to instantiate an object of a class contained in this module. Just a warning about reload(), as your question was already answered: Reloading modules may seem convenient at first, but can lead to strange errors as existing objects are not updated: import module obj = module.SomeClass() reload(module) module 'module' from 'module.pyc' isinstance(obj, module.SomeClass) False Personally I avoid reload() (and importing the main script which leads to similar problems). ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unit test case
On 23/02/13 06:14, jitendra gupta wrote: I am working one tool, which will do compile/run the workspace (that code is written on c/c++). on that my requirment is i need to compile subfolder also, i have wrote code for that also. Just to clarify. You are writing a tool in Python that will compile and run C/C++ code? I assume that the actual compilation is being done by some other tool? You are not writing a C compiler in Python? Is that right so far? My problem is , i am unable to write the Unit test case for that. I'm not sure which bit you can't write the unit test for. Can you be more specific? Also what unit test framework are you using? And while we are at it which OS and which Python version? And finally which C/C++ tools are you using to do the compilation? make? VisualStudio? XCode? gcc? Since my method (called run_subfolder) is not retrurning any thing (this will create one command line argument in that i am adding subfolder condition and passing to the another class which will do actual thing) . Nope, you lost me there. What is creating a command line argument? Which command line? Where is the other class? Is it defined inside run_subfolder? For this method i need to write unit test case. Since i dont have to workspace also , so that i can test this case . Please Sorry, what do you mean by Workspace in this context? advise on this. what i need to do. this is possible or not, if not why. Sorry, I don't understand enough of what you are trying to do to comment. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] getting and using information dict objects
Hi, I am trying to make a move from excel to python. My main need is economic data -- to do economic analysis. I have found the FRED package, and appear to have connected to the St Louis Fed's FRED and downloaded some data, but i'm not sure what to do with the objects that are returned. _ import fred fred.key(fredKey) (i guessed that i should not provide my own FRED API key) gnp = fred.series('GNPCA') i can see that the object returned is a dict type(gnp) type 'dict' but i cannot see how to access the observations, or use them in any way. After a bit of fiddling about, i managed to find another method, which i think also returns a dictionary of values and meta-data: gnpObvs = fred.observations('GNPCA') however I cannot figure out how to get the observation values out and use them. I may be thinking in the wrong framework -- i guess i'm expecting something that is an intuitive as an excel table. The end game for me is making plots of variables, combining them, and doing regressions -- i cannot see how i might take what i'm getting from these FRED / Python dicts to actual data analysis. Could someone please help me take these first steps? thanks + best regards matt ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting and using information dict objects
I am trying to make a move from excel to python. My main need is economic data -- to do economic analysis. If you say Python and Excel the first thing that comes to mind is the xlrd package snip The end game for me is making plots of variables, combining them, and doing regressions -- i cannot see how i might take what i'm getting from these FRED / Python dicts to actual data analysis. Could someone please help me take these first steps? I'm not familiar with the Fred package. Pandas (http://pandas.pydata.org/) seems to be perfect for what you're doing. It's an R-like layer on top of numpy. It can be used to read Excel and many other formats and it works well with matplotlib. It's a cool tool to manipulate/massage/munge data, then analyze it (though R has still more, often ueber-exotic, stats). Its origin lies in the analysis of... economic data. Best used with IPython. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting and using information dict objects
On 02/23/2013 04:56 PM, Matthew Johnson wrote: Hi, I am trying to make a move from excel to python. My main need is economic data -- to do economic analysis. I have found the FRED package, and appear to have connected to the St Louis Fed's FRED and downloaded some data, but i'm not sure what to do with the objects that are returned. _ import fred fred.key(fredKey) (i guessed that i should not provide my own FRED API key) gnp = fred.series('GNPCA') i can see that the object returned is a dict type(gnp) type 'dict' but i cannot see how to access the observations, or use them in any way. After a bit of fiddling about, i managed to find another method, which i think also returns a dictionary of values and meta-data: gnpObvs = fred.observations('GNPCA') however I cannot figure out how to get the observation values out and use them. I may be thinking in the wrong framework -- i guess i'm expecting something that is an intuitive as an excel table. The end game for me is making plots of variables, combining them, and doing regressions -- i cannot see how i might take what i'm getting from these FRED / Python dicts to actual data analysis. Could someone please help me take these first steps? thanks + best regards matt ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Basic use of dictionaries is: d = dict(x=1, y=2) for key, val in d.items(): print(key, val) print d['x'] print d['y'] -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting and using information dict objects
On 23/02/13 21:56, Matthew Johnson wrote: I am trying to make a move from excel to python. My main need is economic data -- to do economic analysis. Any particular reason for moving to Python? I know this is a Python list and we are all Python fans but, frankly, it sounds like your needs might be better met with R. There are Python bindings for R but, honestly, I think raw R might suit what you want better. You can read Excel data into a data frame and then slice and dice it any which way you want. The right tool for the job... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting and using information dict objects
I can see i was being unclear: i wish to replace my analysis in excel with analysis in python. I am fairly sure i am querying the FRED API, but i am unsure how to _access and use_ the dict objects that it is returning. For example, how would i just print out values? Thanks for your help On 24/02/2013, at 9:12 AM, Albert-Jan Roskam fo...@yahoo.com wrote: I am trying to make a move from excel to python. My main need is economic data -- to do economic analysis. If you say Python and Excel the first thing that comes to mind is the xlrd package snip The end game for me is making plots of variables, combining them, and doing regressions -- i cannot see how i might take what i'm getting from these FRED / Python dicts to actual data analysis. Could someone please help me take these first steps? I'm not familiar with the Fred package. Pandas (http://pandas.pydata.org/) seems to be perfect for what you're doing. It's an R-like layer on top of numpy. It can be used to read Excel and many other formats and it works well with matplotlib. It's a cool tool to manipulate/massage/munge data, then analyze it (though R has still more, often ueber-exotic, stats). Its origin lies in the analysis of... economic data. Best used with IPython. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting and using information dict objects
I am fairly sure i am querying the FRED API, but i am unsure how to _access and use_ the dict objects that it is returning. For example, how would i just print out values? If it's a dict object, the standard dictionary behavior and methods should work. I've not looked closely at the FRED API, but something like (untested): for key in dictionary: print(key, dictionary[key]) could possibly get you started. -- best regards, Robert S. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting and using information dict objects
Thanks very much; hopefully that's the boost i need to get rolling. Best regards matt On 24/02/2013, at 10:40 AM, Robert Sjoblom robert.sjob...@gmail.com wrote: I am fairly sure i am querying the FRED API, but i am unsure how to _access and use_ the dict objects that it is returning. For example, how would i just print out values? If it's a dict object, the standard dictionary behavior and methods should work. I've not looked closely at the FRED API, but something like (untested): for key in dictionary: print(key, dictionary[key]) could possibly get you started. -- best regards, Robert S. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting and using information dict objects
For the sake of those who finds this thread -- the date / value pairs can be printed by the following: import fred fred.key(fredKey) gnpObvs = fred.observations('GNPCA') for i in range(1, len(gnpObvs['observations']['observation'])): print gnpObvs['observations']['observation'][i]['date'], gnpObvs['observations']['observation'][i]['value'] mj On 24 February 2013 10:51, Matthew Johnson mcoog...@gmail.com wrote: Thanks very much; hopefully that's the boost i need to get rolling. Best regards matt On 24/02/2013, at 10:40 AM, Robert Sjoblom robert.sjob...@gmail.com wrote: I am fairly sure i am querying the FRED API, but i am unsure how to _access and use_ the dict objects that it is returning. For example, how would i just print out values? If it's a dict object, the standard dictionary behavior and methods should work. I've not looked closely at the FRED API, but something like (untested): for key in dictionary: print(key, dictionary[key]) could possibly get you started. -- best regards, Robert S. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting and using information dict objects
On 02/23/2013 09:40 PM, Matthew Johnson wrote: For the sake of those who finds this thread -- the date / value pairs can be printed by the following: import fred fred.key(fredKey) gnpObvs = fred.observations('GNPCA') for i in range(1, len(gnpObvs['observations']['observation'])): print gnpObvs['observations']['observation'][i]['date'], gnpObvs['observations']['observation'][i]['value'] mj You can do this in a simpler way (in python 2.x): observation = gnpObvs[observation][observation] for obsdict in observation.values()[1:]: print obsdict[date] if you need the 'i' counter, you can do: for i, obsdict in enumerate(observation.values())[1:]: print obsdict[date] HTH, -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ Do whatever you will, but first be such as are able to will. Friedrich Nietzsche ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting and using information dict objects
On 02/23/2013 09:40 PM, Matthew Johnson wrote: For the sake of those who finds this thread -- the date / value pairs can be printed by the following: import fred fred.key(fredKey) gnpObvs = fred.observations('GNPCA') for i in range(1, len(gnpObvs['observations']['observation'])): print gnpObvs['observations']['observation'][i]['date'], gnpObvs['observations']['observation'][i]['value'] mj So it's returning a dict of dicts of lists of dicts? Perhaps this loop would read better (untested): for item in gnpObvs['observations']['observation']: print item['date'], item['value'] -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor