Re: [Tutor] Python open source for beginners
Thanks Wesley for the reply. I wanted to utilize what I've learnt so far. So I thought learning using open source could be a good idea. Thanks. Warm Regards, Mitesh H. Budhabhatti On Thu, Jul 17, 2014 at 10:25 AM, wesley chun wrote: > > > I am learning Python 3 for fun and as hobby. I am experienced in C#, > > ASP.Net. I want to gain more knowledge in Python. Can somebody > > please suggest open source projects/sites? > > > Greetings Mitesh, and welcome to Python! > > Others will have more advice to give on specific projects, but I would initially suggest: 1) http://python.org which is the main website for the open source language -- it has all the docs and a beginners' tutorial, 2) http://ironpython.net which is the website for IronPython, the open source version of Python implemented for .NET, an area that you're familiar with, and where you may feel more comfortable joining the Python world. Finally, 3) http://sf.net/projects/pywin32 -- this is the Python Extensions for Windows library which allows you to create apps using the MFC library, including COM clients. > > As you start coding and running into issues/problems, feel free to drop by and ask your questions here along with a description of what you tried, what didn't work, and what was the output and/or stack trace that you got. > > Best of luck! > --Wesley > > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > "A computer never does what you want... only what you tell it." > +wesley chun : wescpy at gmail : @wescpy > Python training & consulting : http://CyberwebConsulting.com > "Core Python" books : http://CorePython.com > Python blog: http://wescpy.blogspot.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about style
Hello, On 07/17/2014 12:05 AM, Alan Gauld wrote: Just throwing this idea in without really thinking about it... Would itertools.groupby work? It takes a sorted collection and groups the items found based on a key function. If the key function deemed two items identical if they were within distance X of each other then groupby might help. The itertools functions are generally space efficient and therefore good for large volumes of data. Thanks for the suggestion, I didn't know about groupby. I gave it a try. The key function argument is optional; if we don't supply one, grouby groups *equal* list elements. But I want to group *close enough* elements (close enough meaning that their distance is less than some reference value), and I didn't manage to specify a key function in a form suitable for use with groubpy. I should spend some more time studying the examples. Anyway, thanks a lot, it's always good to know a new module in the standard library. Ze ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Surprising behaviour of optional argument
Hello I stumbled on something I found surprising. I'm using standard python (cpython, I guess) 2.7 on openSuse 13.1. Consider the function In [2]: def f(x,y=[]): ...: print y ...: y.append(x) ...: return x This is the output of repeated calls to this function: In [3]: f(1) [] Out[3]: 1 In [4]: f(2) [1] Out[4]: 2 In [5]: f(3) [1, 2] Out[5]: 3 So, the function seems to keep the value of the optional argument y over repeated calls. I was expecting that the optional argument, if not set explicitly in the calling command, would always assume the default value (the empty list), at every call. I guess it has something to do with the mutability of the optional argument (in this case, a list), because it works as I expect if the optional argument is an int, for instance: In [8]: def g(x,y=0): ...: print y ...: y += x ...: return x ...: In [9]: g(1) 0 Out[9]: 1 In [10]: g(2) 0 Out[10]: 2 (No memory of previous calls to the function.) Is there a rationale for this behavior? Thanks for any help, Ze ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Surprising behaviour of optional argument
On Jul 17, 2014 10:22 AM, "Jose Amoreira" wrote: > > Hello > I stumbled on something I found surprising. I'm using standard python (cpython, I guess) 2.7 on openSuse 13.1. > > Consider the function > > In [2]: def f(x,y=[]): >...: print y >...: y.append(x) >...: return x > Yeah; the default value is not reevaluated between calls. It's a common gotcha. Here are a few links to read more: http://effbot.org/zone/default-values.htm http://docs.python-guide.org/en/latest/writing/gotchas/#mutable-default-arguments Good luck! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Modules to work with curl.
Hi, I am currently working on a project , which has lots of curl commands. I am using subprocess.Popen to run these curl commands. But somehow i see its bit slow. Is there a way/module by which i can improve the performance of the program. Thanks, -- D. Santosh Kumar RHCE | SCSA +91-9703206361 Every task has a unpleasant side .. But you must focus on the end result you are producing. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Modules to work with curl.
On Thu, Jul 17, 2014 at 11:35 AM, Santosh Kumar wrote: > I am currently working on a project , which has lots of curl commands. I am > using subprocess.Popen to run these curl commands. But somehow i see its bit > slow. > Is there a way/module by which i can improve the performance of the program. If the use of curl really is responsible and worthwhile to optimize, then you might consider using pycurl if you really need the full features of curl. http://pycurl.sourceforge.net/ But can you say more what you're doing with curl? More information may let us give better advice. The core lesson of http://www.cs.bell-labs.com/cm/cs/pearls/cto.html is always in my mind: we may not actually know the right question yet, so we must be careful about our answers, lest we mislead. I don't think we really understand the problem yet, so tell us more if you can. I would also recommend profiling if you haven't done so already. You've pointed out that something is slow, but unless you've actually measured what's really responsible, anything could be contributing. It may be, for example, that you're being limited by your network throughput, in which case trying to make your program go faster will not be effective. You really must measure: otherwise, it's guesswork and crossed fingers. See: https://docs.python.org/2/library/profile.html for documentation on Python profiling. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Modules to work with curl.
Hi, : I am currently working on a project , which has lots of curl : commands. I am using subprocess.Popen to run these curl commands. : But somehow i see its bit slow. Is there a way/module by which i : can improve the performance of the program. Wow. Is curl a requirement or do you simply need to speak HTTP? Some suggestions and questions come to my mind: * Is your problem / cost the forking (i.e. how many times are you calling curl)? * Is the problem unresponsive or sluggish HTTP servers? * Have you localized the slowness? (I use logging data and timing information to try to figure that out.) * How do you define 'slow'? How many curl commands is 'lots'? Like 100 or 100,000? Suggestions: * Profile the code and see where the slowness is. * Consider python-requests [0] to handle the HTTP fetches, instead of calling subprocess. * If after that, you discover that your bottleneck is mostly network, consider a task parallelizing solution. One option could be multiprocessing [1]. There are doubtless others. -Martin [0] http://docs.python-requests.org/en/latest/ [1] https://docs.python.org/2/library/multiprocessing.html -- Martin A. Brown http://linux-ip.net/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about style
On 17/07/2014 17:23, Jose Amoreira wrote: Hello, On 07/17/2014 12:05 AM, Alan Gauld wrote: Just throwing this idea in without really thinking about it... Would itertools.groupby work? It takes a sorted collection and groups the items found based on a key function. If the key function deemed two items identical if they were within distance X of each other then groupby might help. The itertools functions are generally space efficient and therefore good for large volumes of data. Thanks for the suggestion, I didn't know about groupby. I gave it a try. The key function argument is optional; if we don't supply one, grouby groups *equal* list elements. But I want to group *close enough* elements (close enough meaning that their distance is less than some reference value), and I didn't manage to specify a key function in a form suitable for use with groubpy. I should spend some more time studying the examples. Anyway, thanks a lot, it's always good to know a new module in the standard library. Ze Also take a look at the operator module https://docs.python.org/3/library/operator.html#module-operator as it's often used with itertools. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Surprising behaviour of optional argument
Hi On 07/17/2014 06:34 PM, Danny Yoo wrote: Yeah; the default value is not reevaluated between calls. It's a common gotcha. Here are a few links to read more: http://effbot.org/zone/default-values.htm http://docs.python-guide.org/en/latest/writing/gotchas/#mutable-default-arguments Good luck! Aha, the object that stores the default value for the optional argument is created at the time of the execution of the function definition and mutable objects do mutate, so that's that. It makes a lot of sense. Thanks, Danny ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Surprising behaviour of optional argument
On 17/07/14 23:00, Jose Amoreira wrote: Aha, the object that stores the default value for the optional argument is created at the time of the execution of the function definition and mutable objects do mutate, so that's that. It makes a lot of sense. Yes, think of it as a feature, not a bug :-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Using module Facebook
Dear All, I'm trying to use the facebook-sdk for python [1]. I'm asking here and not on the SDK groups, because I think this is a basic beginner's question, not directly related to the framework. I installed facebook-sdk: virtualenv . source bin/activate pip install facebook-sdk pip install requests and I'm trying to use it now: #!/usr/bin/python from facebook import Facebook token = 'xxx' graph = facebook.GraphAPI(token) profile = graph.get_object("me") friends = graph.get_connections("me", "friends") friend_list = [friend['name'] for friend in friends['data']] print friend_list but I'm getting the following error: (facebook)[chris@cd facebook]$ ./fb1.py Traceback (most recent call last): File "./fb1.py", line 3, in from facebook import Facebook ImportError: No module named facebook facebook.py is in: ./lib/python2.6/site-packages/facebook.py Thank you in advance. [1] https://github.com/pythonforfacebook/facebook-sdk -- Christian ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] R: Tutor Digest, Vol 125, Issue 49
DISCLAIMER* I have deliberately not read any of the other replies to this problem so my answer may be totally redundant! (but here it is anyway...) One of the first issues that had to be addressed is the fact that your "CSV" file is probably not in the format you assume it is. Every line is a list, not the traditional "string separated by commas" format that one normally expects in a CSV file. One way to deal with that is to resave the file as a .txt file and deal with each line as one would normally do with a list, i.e. use list subscripting to manipulate each list element with regex code. Having said that, in the spirit of minimalism, there are ways to deal with it as a CSV file as well. First, import the csv module and use the reader() method to properly access the contents. importre importcsv withopen(/'non.csv'/, /'r'/) asp: f = csv.reader(p, delimiter = /','/) Then use a for loop to access each line and put the regex statements in the print statement forw inf: print(re.sub(r/'(\.\d)'/,/''/,w[0]), re.sub(r/'(\.\d)'/,/''/, w[1])) The regex statements access the list elements with subscripting. The "$" was not necessary and without it you get the desired results. TO SUMMARIZE: With the following contents of file named "non.csv": ['uc002uvo.3 ', 'uc001mae.1'] ['uc010dya.2 ', 'uc001kko.2'] and the following code run in Eclipse: ##test.py importre importcsv withopen(/'non.csv'/, /'r'/) asp: f = csv.reader(p, delimiter = /','/) forw inf: print(re.sub(r/'(\.\d)'/,/''/,w[0]), re.sub(r/'(\.\d)'/,/''/, w[1])) I get: ['uc002uvo ''uc001mae'] ['uc010dya ''uc001kko'] On 7/16/14, 4:04 AM, jarod...@libero.it wrote: Hi there!!! I have a file with this data ['uc002uvo.3 ', 'uc001mae.1'] ['uc010dya.2 ', 'uc001kko.2'] ['uc003ejx.2 ', 'uc010yfr.1'] ['uc001bhk.2 ', 'uc003eib.2'] ['uc001znc.2 ', 'uc001efn.2'] ['uc002ycq.2 ', 'uc001vnh.2'] ['uc001odf.1 ', 'uc002mwd.2'] ['uc010jkn.1 ', 'uc010luk.1'] ['uc003uhf.3 ', 'uc010tqd.1'] ['uc002rue.3 ', 'uc001tex.2'] ['uc011dtt.1 ', 'uc001lkv.1'] ['uc003yyt.2 ', 'uc003mkl.2'] ['uc003pkv.2 ', 'uc003ytw.2'] ['uc010bhz.2 ', 'uc002kbt.1'] ['uc001wnj.2 ', 'uc009wtj.1'] ['uc011lyh.1 ', 'uc003jvb.2'] ['uc002awj.1 ', 'uc009znm.1'] ['uc010bft.2 ', 'uc002cxz.1'] ['uc011mar.1 ', 'uc001lvb.1'] ['uc001oxl.2 ', 'uc002lvx.1'] I want to replace of the things after the dots, so I want to have a file with this output: ['uc002uvo ', 'uc001mae'] ['uc010dya ', 'uc001kko'] ... I try to use regular expression but I have a strange output with open("non_annotati.csv") as p: for i in p: lines= i.rstrip("\n").split("\t") mit = re.sub(r'(\.\d$)','',lines[0]) mit2 = re.sub(r'(\.\d$)','',lines[1]) print mit,mit2 uc003klv.2 uc010lxj uc001tzy.2 uc011kzk uc010qdj.1 uc001iku uc004coe.2 uc002vmf uc002dvw.2 uc004bxn uc001dmp.2 uc001dmo uc002rqd.2 uc010ynl uc010cvm.1 uc002qjc uc003ewy.3 uc003hgx uc002ejy.2 uc003mvb uc002fou.1 uc010ilx uc003vhf.2 uc010qlo uc003mix.2 uc010tdt uc002nez.1 uc003wxe uc011cpu.1 uc002keg uc001ovu.2 uc011dne uc010zfg.1 uc001jvq uc010jlf.2 uc011azi uc001ors.3 uc001vzx uc010tyt.1 uc003vih uc010fde.2 uc002xgq uc010bit.1 uc003zle uc010xcb.1 uc010wsg uc011acg.1 uc009wlp uc002bnj.2 uc004ckd Where is the error? what is wrong in my regular expression code? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor