Re: [Tutor] Help with python-gnupg
On Sat, Mar 12, 2011 at 2:07 AM, David Hutto wrote: > As a matter of fact, looking at them with know *no* knowledge of the > module, it says it's a typeerror, and that it expects string or > buffer, but gets file. If this is the same error in both instances, > then it's that output needs to be a string or buffer, so just string > either the datae variable, or the output variable. > -- According to theoretical physics, the division of spatial intervals as the universe evolves gives rise to the fact that in another timeline, your interdimensional counterpart received helpful advice from me...so be eternally pleased for them. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with python-gnupg
As a matter of fact, looking at them with know knowledge of the module, it says it's a typeerror, and that it expects string or buffer, but gets file. If this is the same error in both instances, then it's that output needs to be a string or buffer, so just string either the datae variable, or the output variable. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with python-gnupg
On Sat, Mar 12, 2011 at 1:39 AM, Becky Mcquilling wrote: > If anyone is familiar with python-gnupg, I am having some difficulty with > the syntax. I've tried the following: > f = open('c:/test/filename.txt', 'r') > datae = gpg.encrypt_file(f.read(), 'ladym...@gmail.com', > output=open('c:/gpg_test/data.gpg2', 'w')) > > or > file_to_encrypt = open('c:/gpg_test/data.gpg2', 'w') > datae = gpg(f.read(), 'ladym...@gmail.com', output=file_to_encrypt) > Either way, I can't get the output written to a file, it gives me an error: > Traceback (most recent call last): > File "", line 1, in > datae = gpg.encrypt_file(f.read(), 'becky...@google.com', > output=open('c:/test/data.gpg2', 'w')) > File "C:\Python27\lib\site-packages\gnupg.py", line 583, in encrypt_file > if os.path.exists(output): > File "C:\Python27\lib\genericpath.py", line 18, in exists > os.stat(path) > TypeError: coercing to Unicode: need string or buffer, file found This seems to say it needs a string or buffer, but a file was found. Which says to me, you need to convert the file that is found to a string before passing it as a parameter to a function. It might be that output needs to be a string before it is used, so read the file and string it. It's just a guess from what I see though. > Any thoughts? Would reallly appreciate the help. > If you aren't familiar with this and know of resources, it would be awesome. > > Becky > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- According to theoretical physics, the division of spatial intervals as the universe evolves gives rise to the fact that in another timeline, your interdimensional counterpart received helpful advice from me...so be eternally pleased for them. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with python-gnupg
Show the entire code, and error for both usages. The usages and a single error message for them both may be enough for someone not to try them out, and who can help you, if they knew more about the problem. Not everyone here will be an expert, but we do read direct code vs direct error, if we've been paying attention. Plus, we can try the whole code out, and see what you're trying to do altogether instead of in a specific portion that may misrepresent the whole of the problem. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with python-gnupg
If anyone is familiar with python-gnupg, I am having some difficulty with the syntax. I've tried the following: f = open('c:/test/filename.txt', 'r') datae = gpg.encrypt_file(f.read(), 'ladym...@gmail.com', output=open('c:/gpg_test/data.gpg2', 'w')) or file_to_encrypt = open('c:/gpg_test/data.gpg2', 'w') datae = gpg(f.read(), 'ladym...@gmail.com', output=file_to_encrypt) Either way, I can't get the output written to a file, it gives me an error: Traceback (most recent call last): File "", line 1, in datae = gpg.encrypt_file(f.read(), 'becky...@google.com', output=open('c:/test/data.gpg2', 'w')) File "C:\Python27\lib\site-packages\gnupg.py", line 583, in encrypt_file if os.path.exists(output): File "C:\Python27\lib\genericpath.py", line 18, in exists os.stat(path) TypeError: coercing to Unicode: need string or buffer, file found Any thoughts? Would reallly appreciate the help. If you aren't familiar with this and know of resources, it would be awesome. Becky ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Resources
On 03/11/2011 09:19 PM, s s wrote: Hello, I was wondering where I should go to improve my python skills. I have finished the official tutorial and the tutorials on the official python website. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Look at this page and pick your challenge. Have a great time. http://sixrevisions.com/resources/10-puzzle-websites-to-sharpen-your-programming-skills/ HTH, Robert ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Resources
Hello, I was wondering where I should go to improve my python skills. I have finished the official tutorial and the tutorials on the official python website. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sorting multiple sequences
Dinesh B Vadhia wrote: I want to sort two sequences with different data types but both with an equal number of elements eg. f = [0.21, 0.68, 0.44, ..., 0.23] i = [6, 18, 3, ..., 45] The obvious solution is to use zip ie. pairs = zip(f,i) followed by pairs.sort(). This is fine It doesn't sound fine to me. Sorting pairs of items is *not* the same as sorting each sequence separately, except by accident. Even with the small example shown, you can see this: >>> f = [0.21, 0.68, 0.44, 0.23] >>> i = [6, 18, 3, 45] >>> sorted(f); sorted(i) # sorting individually [0.21, 0.23, 0.44, 0.68] [3, 6, 18, 45] >>> pairs = sorted(zip(f, i)) # sorting as pairs >>> print(pairs) [(0.21, 6), (0.23, 45), (0.44, 3), (0.68, 18)] >>> list(zip(*pairs)) # Split the pairs into separate sequences. [(0.21, 0.23, 0.44, 0.68), (6, 45, 3, 18)] In Python, the fastest way to sort multiple sequences is to sort multiple sequences. No tricks, nothing fancy, just: f.sort() i.sort() Don't use sorted() unless you have to keep the unsorted list as well, because sorted makes a copy of the data. In other words, don't do this: f = sorted(f) # No! Bad! but you can do this: old_f = f f = sorted(f) but my sequences contain 10,000+ elements and the sort is performed thousands of times. Is there a faster solution? Ten thousand elements is not very many. Why do you need to sort thousands of times? What are you doing with the data that it needs repeated sorting? Python's sort routine is implemented in C, highly optimized, and is extremely fast. It is especially fast if the data is already almost sorted. So if you have a list of sorted data, and you add one item to the end, and re-sort, that will be *extremely* fast. There is literally nothing you can write in pure Python that will even come close to the speed of Python's sort. Unless you have profiled your application and discovered that sorting is the bottleneck making the app too slow, you are engaged in premature optimization. Don't try and guess what makes your code slow, measure! -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sorting multiple sequences
On 3/11/2011 3:39 PM Dinesh B Vadhia said... I want to sort two sequences with different data types but both with an equal number of elements eg. f = [0.21, 0.68, 0.44, ..., 0.23] i = [6, 18, 3, ..., 45] The obvious solution is to use zip ie. pairs = zip(f,i) followed by pairs.sort(). This is fine but my sequences contain 10,000+ elements and the sort is performed thousands of times. Is there a faster solution? Sort only once? If you describe your situation better you may get more helpful responses, but if you really want to sort 1000's of times I doubt there's anything mush faster that pairs.sort()... Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Sorting multiple sequences
I want to sort two sequences with different data types but both with an equal number of elements eg. f = [0.21, 0.68, 0.44, ..., 0.23] i = [6, 18, 3, ..., 45] The obvious solution is to use zip ie. pairs = zip(f,i) followed by pairs.sort(). This is fine but my sequences contain 10,000+ elements and the sort is performed thousands of times. Is there a faster solution? Dinesh ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New person greets you all!
On 3/11/2011 2:44 PM Yaşar Arabacı said... I see all of you guys suggest that starting with 3.x. I was wondering what is setback of starting with 2.7 since my linux distro (openSUSE 11.4) comes with it and it would be pretty painfull for me to update to 3.x because lots of my applications in my computer depends on it. So is it worth the trouble of updating? No. In fact, someone made the point earlier today, either here or on the main list, that linux administration scripts play nicer with 2.7 vs 3.x related somehow to unicode. Further, many useful third party libraries have not yet been ported to 3.x, so many of us (me included) haven't yet made the jump to 3.x. Just be aware that the two exist and the info you find on the net may not apply. Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New person greets you all!
I see all of you guys suggest that starting with 3.x. I was wondering what is setback of starting with 2.7 since my linux distro (openSUSE 11.4) comes with it and it would be pretty painfull for me to update to 3.x because lots of my applications in my computer depends on it. So is it worth the trouble of updating? If that is really necessary, I think I can find some help in OpenSuse forums. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New person greets you all!
"Knacktus" wrote The official Python tutorial is a good start. You get familiar with the Python documentation as well. http://docs.python.org/py3k/ (Find the link to the tutorial on this page.) If you can already program thats the best starting point. For many folks its all they need. A classic and famous tutorial is here: http://www.alan-g.me.uk/ Thanks for the kind words :-) However it is really aimed at true beginners It tries to get you to the stage where the official documentation makes sense! :-) Another classic is "Dive into Python". You can find it easily with google. This is probably a better followup to the official tutorial for an experienced programmer than mine. And remember to ask questions here as you go! PS. I didn't found this group but I did join it near the beginning and started writing my tutorial using the common questions here to direct a lot of the content. -- Alan Gauld 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] CSV to Excel
On Fri, Mar 11, 2011 at 3:59 PM, Susana Iraiis Delgado Rodriguez < susana.delgad...@utzmg.edu.mx> wrote: > Hello list!! > > I'm trying to write a CSV file to work it with Excel. My python script is > working, the issue is: when I import the file from excel the data comes with > quotes at the beginnig and ending of the row. I don't want to have these > quotes. What is wrong with my code? > > import os, csv > from osgeo import ogr,gdal,osr > from dbf import * > gdal.AllRegister() > file_list = [] > folders = None > for root, folders, files in os.walk( "C:\\" ): > file_list.extend(os.path.join(root,fi) for fi in files if > fi.endswith(".shp")) > writer = csv.writer(open('csv2.csv', "wb")) > campos = ['Ruta,Archivo,.prj'] > writer.writerow(campos) > for row, filepath in enumerate(file_list, start=1): > (ruta, filename) = os.path.split(filepath) > n = os.path.splitext(filepath) > p = n[0]+'.prj' > if os.path.exists(p): > aRow = [""+filepath+","+filename+",1"] > I think your problem is in the line above. If you remove the extra quotes the problem goes away >>> filepath = 'filepath' >>> filename = 'filename' >>> aRow = [filepath,filename,1] >>> aRow ['filepath', 'filename', 1] writer.writerow(aRow) > else: > aRow1 = [""+filepath+","+filename+",0"] > writer.writerow(aRow1) > print "El archivo esta listo" > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- Joel Goldstick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] CSV to Excel
On 11/03/2011 8:59 PM, Susana Iraiis Delgado Rodriguez wrote: Hello list!! I'm trying to write a CSV file to work it with Excel. My python script is working, the issue is: when I import the file from excel the data comes with quotes at the beginnig and ending of the row. I don't want to have these quotes. What is wrong with my code? Essentially, the work is being done twice. The .writerow method expects a list which it will convert into a quoted, comma-separated string. You're giving it a list whose one element is a quoted, comma-separated string. Just pass it a list instead: writer.writerow (['Ruta', 'Archivo', '.prj']) ... writer.writerow ([filepath, filename, 1]) (BTW, my naive knowledge of Spanish suggests that you're confusing the two identical-sounding English words: "root" -> "raiz" and "route" -> "ruta"). TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] CSV to Excel
Hello list!! I'm trying to write a CSV file to work it with Excel. My python script is working, the issue is: when I import the file from excel the data comes with quotes at the beginnig and ending of the row. I don't want to have these quotes. What is wrong with my code? import os, csv from osgeo import ogr,gdal,osr from dbf import * gdal.AllRegister() file_list = [] folders = None for root, folders, files in os.walk( "C:\\" ): file_list.extend(os.path.join(root,fi) for fi in files if fi.endswith(".shp")) writer = csv.writer(open('csv2.csv', "wb")) campos = ['Ruta,Archivo,.prj'] writer.writerow(campos) for row, filepath in enumerate(file_list, start=1): (ruta, filename) = os.path.split(filepath) n = os.path.splitext(filepath) p = n[0]+'.prj' if os.path.exists(p): aRow = [""+filepath+","+filename+",1"] writer.writerow(aRow) else: aRow1 = [""+filepath+","+filename+",0"] writer.writerow(aRow1) print "El archivo esta listo" ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Using the console module.
"DistortGiygas" wrote Python users, what's the best option for someone trying to emulate or use the curses module on the Windows platform? Write a GUI? Unlike Unix you know that you can run a GUI on windows so why not just write one. Its probably easier than using curses! But for the life of me, I can't figure out how to detect a KeyRelease. You need the key release rather than the keypress? I'm not sure curses can do that. I'm no curses expert though, but I've never seen it done. Console terminals don't always have the same level of fine grained events that a GUI has... For keypresses see the curses example in my tutorial (under event handling). But you still need a Windows version. PS. If you really need it you could try the Cygwin version of Python which comes with curses support... But then your users need cygwin installed too. But that might not be an issue... And if its for personal use, well, every Python Windows programmer should have cygwin installed! ;-) -- Alan Gauld 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] Help on reading a plain file of names
"Tiago Cunha" wrote I would suggest to use the NLTK package. Try methods like nltk.endswith() or nltk.startswith() NLTK is probably overkill. The standard string methods startswith() and endswith() are probably adequate for this case. Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with dates in Python
Thanks for your help Francesco. This works. Sree. --- On Fri, 3/11/11, Francesco Loffredo wrote: > From: Francesco Loffredo > Subject: Re: [Tutor] Need help with dates in Python > To: tutor@python.org > Date: Friday, March 11, 2011, 1:05 AM > On 09/03/2011 9.21, nookasree > ponamala wrote: > > Hi, > > > > I need help in finding the minimum date and maximum > date in a file. > > Here is my test file: > > s.no: dt1 > amt id1 id2 > > 452 2010-02-20 > $23.26 059542 > 06107 > > 452 2010-02-05 > $20.78 059542 > 06107 > > 451 2010-02-24 > $5.99 059542 > 20151 > > 452 2010-02-12 > $114.25 839745 > 98101 > > 452 2010-02-06 > $28.00 839745 > 06032 > > 451 2010-02-12 > $57.00 839745 > 06269 > > > > I want to get the minimum and maximum dt1 for each > id1 > > > > Required result: > > > > id1 mindate maxdate > > 059542 2010-02-24 > 2010-02-20 > > 839745 2010-02-06 > 2010-02-12 > > > > Code: The code I tried. It doesn't work though. > > I noticed that your dates are formatted in a way that makes > it easy to compare them as strings. > This allows you not only to do without splitting dates into > year, month and day, but also to do without the datetime > module: > I'm also, AFAIK, the first one to address your need for the > min and max date FOR EACH ID1, not in the whole file. > > . ids = {} # create an empty dictionary > to store results > . for L in open("test.txt", "r"): > . S = L.split() # allow direct > access to fields > . if S[3] in ids: > . mindate, maxdate = > ids[S[3]] # current stored minimum and maximum date > . if S[1] < mindate: > . mindate = S[1] > . if S[1] > maxdate: > . maxdate = S[1] > . ids[S[3]] = (mindate, > maxdate) # new stored min and max > . else: > . ids[S[3]] = (S[1], S[1]) > # initialize storage for the current id1, with min and max > in a tuple > . #leave print formatting as an exercise to > the reader (but you can do without it!) > . print ids > > Hope this helps... > Francesco > > > - > Nessun virus nel messaggio. > Controllato da AVG - www.avg.com > Versione: 10.0.1204 / Database dei virus: 1497/3495 - > Data di rilascio: 09/03/2011 > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New person greets you all!
Hello, I am not a computer major, either. I am a Linguistics doctorate Student. I worked with the basics of programming (C, prolog...). And now using Python for Natural Language Processing. My interests are probably very different from yours, but I got intimate by Wesley Chun's Core Python Programming. Tiago Cunha On Fri, Mar 11, 2011 at 3:18 PM, Knacktus wrote: > Am 11.03.2011 17:12, schrieb Yaşar Arabacı: > >> Hi, >> >> First of all, I want to greet you all since this is the first time I >> will be using this mail groups. >> >> I consider myself being familiar with programming logic, structures in >> general. I do/did lots of PHP programming. I know python and PHP is >> pretty much different things, I am saying this just to show yourself my >> level of understanding on programming. I am not computer major or >> anything, but I am highly interested in. >> >> Today, I decided to make a chat application using python. I have chosen >> python because I know its powerfull and easy to use. The first step for >> me to go should be, clearly, begin learning how to use it :) >> >> My question is, where would you recommend for me to read tutorials, see >> example etc. What is the best approach would be? >> > > The official Python tutorial is a good start. You get familiar with the > Python documentation as well. > http://docs.python.org/py3k/ > (Find the link to the tutorial on this page.) > > A classic and famous tutorial is here: > http://www.alan-g.me.uk/ > If you have any questions about this, you're lucky to be on this list, > because the author of this ressource is very active here. (One of or the > founder of the list?) > > Another classic is "Dive into Python". You can find it easily with google. > There're two versions, Python 2.x and 3.x. By the way, I would recommend > starting with Python 3.2. Some 3rd party libs and web frameworks are not > ported yet, but for your chat app you should be very happy with Python 3.2. > > Recently, a tutorial with a bit of a different style has been finished. I > haven't done it and the style is not my cup of tea, but some people like it > a lot. It's called "Learning Python the hard way". Google for the url... > > Now, welcome to the beach of programming! > > Jan > > >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New person greets you all!
2011/3/11 Yaşar Arabacı > Hi, > > First of all, I want to greet you all since this is the first time I will > be using this mail groups. > Welcome! > I consider myself being familiar with programming logic, structures in > general. I do/did lots of PHP programming. I know python and PHP is pretty > much different things, I am saying this just to show yourself my level of > understanding on programming. I am not computer major or anything, but I am > highly interested in. > I think you'll find that your level of experience is similar to many people here. > Today, I decided to make a chat application using python. I have chosen > python because I know its powerfull and easy to use. The first step for me > to go should be, clearly, begin learning how to use it :) > > My question is, where would you recommend for me to read tutorials, see > example etc. What is the best approach would be? Since you say that you're familiar with basic programming concepts, I would recommend the official tutorial available here: http://python.org/doc/ Since you're just beginning, I will also mention a trap that catches many beginners - currently there are two versions of Python out, 2.x and 3.x - that are incompatible with each other in many of the beginner examples you will see. Currently, there are a fair number of 3rd party libraries that have been ported to 3.x, with many more conversions underway. But many (most?) of the 3rd party packages have not yet been ported. I will recommend two options: either to start learning with 3.x, and then if in the future you find a package that has not been ported yet, you can use Python 3to2 to convert your code. Alternatively, you could start with Python 2.x and use from __future__ import print_function, division, unicode_literals which will give you some of the behavior that is present in Python 3. You stated that you want to develop a chat application, and it's perfectly possible to create a chat application using the tools that are currently available in Python 3. Also, in the inevitable event that you run into problems, remember to post the full error message along with what you did, what you expected to happen, and what happened instead. Usually it's also a good idea to copy and paste your code. Good luck, and happy coding, Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help on reading a plain file of names
I would suggest to use the NLTK package. Try methods like nltk.endswith() or nltk.startswith() On Fri, Mar 11, 2011 at 5:36 AM, Alan Gauld wrote: > "apple owner" wrote > > > I am new to python and I am trying to open a plain >> text file of names and to see the number of names >> that start with specific letters and display them >> in a bar graph. >> > > OK, Lets break that down so that we can understand > what exactly puzzles you: > > 1) Can you open a text file and read it? > 2) Can you figure out if a string(a name) startwith a specific latter? > 3) Can you build a collection based ion the starting letter - a dictionary > maybe? > 4) Can you display the dictionary keys and values on a graph? > > Can you try to solve each part of the problem separately > and then put the pieces together for your final solution? > > Try posting back with specific questions and example code > where you have tried to solve the problem. That makes it > easier for us to se where you are having trouble. > > HTH, > > -- > Alan Gauld > 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 maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New person greets you all!
Am 11.03.2011 17:12, schrieb Yaşar Arabacı: Hi, First of all, I want to greet you all since this is the first time I will be using this mail groups. I consider myself being familiar with programming logic, structures in general. I do/did lots of PHP programming. I know python and PHP is pretty much different things, I am saying this just to show yourself my level of understanding on programming. I am not computer major or anything, but I am highly interested in. Today, I decided to make a chat application using python. I have chosen python because I know its powerfull and easy to use. The first step for me to go should be, clearly, begin learning how to use it :) My question is, where would you recommend for me to read tutorials, see example etc. What is the best approach would be? The official Python tutorial is a good start. You get familiar with the Python documentation as well. http://docs.python.org/py3k/ (Find the link to the tutorial on this page.) A classic and famous tutorial is here: http://www.alan-g.me.uk/ If you have any questions about this, you're lucky to be on this list, because the author of this ressource is very active here. (One of or the founder of the list?) Another classic is "Dive into Python". You can find it easily with google. There're two versions, Python 2.x and 3.x. By the way, I would recommend starting with Python 3.2. Some 3rd party libs and web frameworks are not ported yet, but for your chat app you should be very happy with Python 3.2. Recently, a tutorial with a bit of a different style has been finished. I haven't done it and the style is not my cup of tea, but some people like it a lot. It's called "Learning Python the hard way". Google for the url... Now, welcome to the beach of programming! Jan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] New person greets you all!
Hi, First of all, I want to greet you all since this is the first time I will be using this mail groups. I consider myself being familiar with programming logic, structures in general. I do/did lots of PHP programming. I know python and PHP is pretty much different things, I am saying this just to show yourself my level of understanding on programming. I am not computer major or anything, but I am highly interested in. Today, I decided to make a chat application using python. I have chosen python because I know its powerfull and easy to use. The first step for me to go should be, clearly, begin learning how to use it :) My question is, where would you recommend for me to read tutorials, see example etc. What is the best approach would be? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Code structure help
(...snip...) I think your question is appropriate for both lists, it just wasn't sexy enough for anyone on c.l.py to answer ;) what is not sexy about modelling plant carbon uptake ;P Random remarks: > pg = PlantGrowth(self.control, self.params, self.state, > self.fluxes, self.met_data) I'd prefer your code to be even more verbose here; no two-letter variables for anything that is non-generic. ok so a more thorough name then? I had seen class instances used before with single letters > # plant growth > pg.grow(project_day, self.date, leafnc) With the construction in mind that is actually Sorry don't get this? > # plant growth > plant_growth.grow(project_day, self.date, leafnc) but plant_grows.grow() does not make a lot of sense, and the comment is superfluous as it just undoes the abbreviation instead of explaining what is going on. Yep sorry I haven't gone through and finished all the comments, some of them were placeholders! Agreed grow isn't the best name > # calculate model decay rates > dc.decay_rates() A lot of methods don't take any arguments and return nothing. I'm guessing that they modify the state that you passed to the initializer. I prefer these modifications to be explicit if feasible, e. g. state = dc.decay_rates(state) where of course state is a placeholder for the actual variables that are necessary to do the calculations. yes well i guess that is one of the issues - two objects state and fluxes are modified throughout. So you think it is better to pass these to the methods rather than to the class constructors? If i do it that way I potentially have to then pass it throughout a number of methods in other classes. The way I set it up, I could call it though the self statement, e.g. self.fluxes.some_variable in a various class methods. The big picture? I'll leave that for someone else. thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- View this message in context: http://old.nabble.com/-Tutor--Code-structure-help-tp31124923p31126370.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] very odd math problem
On 01/-10/-28163 02:59 PM, Steven D'Aprano wrote: Alan Gauld wrote: Why would you use a loop when the final value is just the final multiplication. Since you know the final value in advance (you need it to create the loop!) why not just do the final multiplication directly: x = 10*0.1 I think I'm missing something? The context was generating a list of values, not just the final value. But the result can be generalized to other situations. Consider some function that calculates a result x by an iterative process. You don't care about the intermediate results, but you do have to step through them on the way to the final result: x = initial_value while condition: x += increment(x) When possible, it is better to re-write the formula to avoid repeatedly adding an increment to x. The problem is, if each addition has potential error of dx, then N additions have potential error N*dx -- you can't assume that errors will always cancel. If N is large, so is the expected error. I like to think of this as the social security problem, as that was the context in which I first saw it. When figuring social security withholding tax (USA), the employer is not allowed to just figure it on the basis of the current wage amount. If he did, the amount deducted would be rounded/truncated to the penny, and those partial pennies could add up to an enormous amount. Instead he figures the total soc.sec. tax on the pay for the year, and from that subtracts the amount withheld in all previous checks. So the total is always within a fractional penny of the correct amount. Any time you can't store the intermediate amount exactly, you need to decide how/if to eliminate accumulating residuals. DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Code structure help
Martin De Kauwe wrote: > Note I have cross posted this as I have only just found this mailing list > and perhaps it is the more appropriate place (I am not sure)? I think your question is appropriate for both lists, it just wasn't sexy enough for anyone on c.l.py to answer ;) > I have been working on re-writing a model in python. However I am not sure > how easy on the eye my final structure is and would appreciate any > constructive comments/suggestions. So broadly the model estimates how > plants grow using a number of related sub functions which I have grouped > into classes and they all live in separate files. My main issue at the > moment is I think I have a lot of verbose class instances but I really > can't see a better way to do it. Is there a better way? How do other > people do similar things? I am talking largely about the instances in the > method run_sim Random remarks: > pg = PlantGrowth(self.control, self.params, self.state, > self.fluxes, self.met_data) I'd prefer your code to be even more verbose here; no two-letter variables for anything that is non-generic. > # plant growth > pg.grow(project_day, self.date, leafnc) With the construction in mind that is actually > # plant growth > plant_growth.grow(project_day, self.date, leafnc) but plant_grows.grow() does not make a lot of sense, and the comment is superfluous as it just undoes the abbreviation instead of explaining what is going on. > for i in self.met_data.doy: > project_day = i - 1 > self.increment_date() I'd iterate over the project_day-s directly if possible for project_day in self.project_days(): ... > # calculate model decay rates > dc.decay_rates() A lot of methods don't take any arguments and return nothing. I'm guessing that they modify the state that you passed to the initializer. I prefer these modifications to be explicit if feasible, e. g. state = dc.decay_rates(state) where of course state is a placeholder for the actual variables that are necessary to do the calculations. The big picture? I'll leave that for someone else. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] very odd math problem
> >> The right way is to do it like this: > >> > >> >>> x = 0.0 > >> >>> for i in range(1, 11): > >> ... x = i*0.1 > > But this I don't understand. > > Why would you use a loop when the final value is just > > What you missed was the original context, where other work was being > done in the loop, and where the accuracy of the "accumulator" was being > misunderstood. Ah yes, I confess I didn't read the OPs code in detail, I was more interested in Steven's reply. If other things are happening in the loop then that explains things. Thanks Dave. Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python help on unicode needed....
Hello Danny, Can you perhaps help me on a python Unicode issue? I have an audio collection of many chinese titles on my music Database. I would like to rename all music titles in the directories and subdirectories to either their ascii values (preceeding with a certain character/s like “xx-“ or just delete the chinese characters from the dir name and file names. Do you have a simple solution for the batch renaming issue? Many thanks in advance István many thanks! -- the more you give, the more you have ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Code structure help
Hi, Note I have cross posted this as I have only just found this mailing list and perhaps it is the more appropriate place (I am not sure)? I have been working on re-writing a model in python. However I am not sure how easy on the eye my final structure is and would appreciate any constructive comments/suggestions. So broadly the model estimates how plants grow using a number of related sub functions which I have grouped into classes and they all live in separate files. My main issue at the moment is I think I have a lot of verbose class instances but I really can't see a better way to do it. Is there a better way? How do other people do similar things? I am talking largely about the instances in the method run_sim I have left some of the bones of the code out but this is basically what would it looks like. thanks, Martin import constants as const from file_parser import ConfigFileParser from plant_growth import PlantGrowth from print_outputs import PrintOutput from litter import LitterFlows from decomp import DecompFactors from soil_cnflows import CarbonFlows, NitrogenFlows from nmineralisation import Mineralisation from update_pools import CarbonPools, NitrogenPools ...etc... class ModelName(object): def __init__(self, cfg_fname=None): """ Set everything up Read meterological forcing file, any user adjusted files. If there is anything in the user file then adjust the model parameters, control or initial state attributes that are used within the code. """ # sweep the cmd line options, args = cmdline_parser() # quit if asked only to dump default paramater files if options.DUMP_INPUT == True: ...call some stuff... # read in user defined variables (stored in dictionaries) pars = ConfigFileParser(cfg_fname=cfg_fname) (control, params, state, files, fluxes, met_data) = pars.main() # objects holding model state, fluxes, etc self.met_data = met_data self.control = control self.params = params self.state = state self.fluxes = fluxes # instances of other model parts.. self.pr = PrintOutput(self.params, self.state, self.fluxes, self.control, self.files, dump=False) # start date of simulation self.date = self.simulation_start_date() ...etc def run_sim(self): mi = Mineralisation(self.control, self.params, self.state, self.fluxes) cf = CarbonFlows(self.control, self.params, self.state, self.fluxes) nf = NitrogenFlows(self.control, self.params, self.state, self.fluxes) de = Derive(self.control, self.params, self.state, self.fluxes) dc = DecompFactors(self.control, self.params, self.state, self.fluxes) lf = LitterFlows(self.control, self.params, self.state, self.fluxes) pg = PlantGrowth(self.control, self.params, self.state, self.fluxes, self.met_data) cpl = CarbonPools(self.control, self.params, self.state, self.fluxes) npl = NitrogenPools(self.control, self.params, self.state, self.fluxes) for i in self.met_data.doy: project_day = i - 1 # N:C ratios leafnc, rootnc = self.leaf_root_ncratio() # litterfall rate: C and N fluxes lf.flows(leafnc, rootnc) # plant growth pg.grow(project_day, self.date, leafnc) # calculate model decay rates dc.decay_rates() # soil model fluxes cf.calculate_cflows() nf.calculate_nflows() # N uptake and loss mi.calculate_mineralisation() # soil model - update pools cact, cslo, cpas = cpl.calculate_cpools() npl.calculate_npools(cact, cslo, cpas) if self.control.print_options == 1: self.pr.print_state() self.pr.print_fluxes() self.increment_date() if self.control.print_options == 2: self.pr.print_state() self.pr.print_fluxes() # house cleaning, close ouput files self.pr.tidy_up() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] very odd math problem
> Some further resources: > > http://floating-point-gui.de/ > http://introcs.cs.princeton.edu/91float/ > > David Goldberg used to have a fantastic (although quite technical) > discussion of floating point issues, "What Every Computer Scientist Should > Know About Floating-Point Arithmetic": > > http://docs.sun.com/source/806-3568/ncg_goldberg.html > > Found the sun article that Steve was talking about: http://replay.waybackmachine.org/20090227080227/http://docs.sun.com/source/806-3568/ncg_goldberg.html HTH, Tino ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] very odd math problem
On 01/-10/-28163 02:59 PM, Alan Gauld wrote: "Steven D'Aprano" wrote The right way is to do it like this: >>> x = 0.0 >>> for i in range(1, 11): ... x = i*0.1 ... >>> x == 1.0 True But this I don't understand. Why would you use a loop when the final value is just the final multiplication. Since you know the final value in advance (you need it to create the loop!) why not just do the final multiplication directly: x = 10*0.1 I think I'm missing something? What you missed was the original context, where other work was being done in the loop, and where the accuracy of the "accumulator" was being misunderstood. Steven's point was that doing repeated sums of a quantized value is going to lead to a cumulative error, which can be minimized by using integers and scaling. DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] very odd math problem
Alan Gauld wrote: Why would you use a loop when the final value is just the final multiplication. Since you know the final value in advance (you need it to create the loop!) why not just do the final multiplication directly: x = 10*0.1 I think I'm missing something? The context was generating a list of values, not just the final value. But the result can be generalized to other situations. Consider some function that calculates a result x by an iterative process. You don't care about the intermediate results, but you do have to step through them on the way to the final result: x = initial_value while condition: x += increment(x) When possible, it is better to re-write the formula to avoid repeatedly adding an increment to x. The problem is, if each addition has potential error of dx, then N additions have potential error N*dx -- you can't assume that errors will always cancel. If N is large, so is the expected error. If it isn't possible to re-write it, then you have to take care to control for the error, which is hard. This is why good maths software tends to be horrible code, and why pretty code tends to make terrible maths software :( Another source of errors is catastrophic cancellation, when intermediate terms in a calculation cancel so badly that the end result is *completely* wrong. To see an especially extreme example, here's a torture test for summation by Tim Peters: >>> sum([1, 1e100, 1, -1e100] * 1) 0.0 This sum *should* add up to 2: 1 + 1e100 + 1 - 1e100 + 1 ... + 1e100 + 1 - 1e100 = 1 + 1 + 1 + ... + 1 = 2 but due to round-off error at each step, it cancels to zero: >>> sum([1, 1e100, 1, -1e100] * 1) 0.0 The math module starting in Python 2.6 has a specialised high-precision sum function that can cope: >>> import math >>> math.fsum([1, 1e100, 1, -1e100] * 1) 2.0 -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Using the console module.
On 11/03/2011 08:12, DistortGiygas wrote: Python users, what's the best option for someone trying to emulate or use the curses module on the Windows platform? I've been fooling around with the console module: effbot.org/zone/console-handbook.htm But for the life of me, I can't figure out how to detect a KeyRelease. Could anyone share some insight, and maybe an example of how to code it? :( If your starting point is in fact curses, then you're probably better off using a curses-alike for Windows. Christopher Gohlke maintains binaries for one such: http://www.lfd.uci.edu/~gohlke/pythonlibs/ (search for "curses") TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help on reading a plain file of names
"apple owner" wrote I am new to python and I am trying to open a plain text file of names and to see the number of names that start with specific letters and display them in a bar graph. OK, Lets break that down so that we can understand what exactly puzzles you: 1) Can you open a text file and read it? 2) Can you figure out if a string(a name) startwith a specific latter? 3) Can you build a collection based ion the starting letter - a dictionary maybe? 4) Can you display the dictionary keys and values on a graph? Can you try to solve each part of the problem separately and then put the pieces together for your final solution? Try posting back with specific questions and example code where you have tried to solve the problem. That makes it easier for us to se where you are having trouble. HTH, -- Alan Gauld 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] very odd math problem
"Steven D'Aprano" wrote Another problem: you calculate your values by repeated addition. This is the wrong way to do it, because each addition has a tiny little error, and repeating them just compounds error upon error. Here's an example: >>> x = 0.0 >>> for i in range(10): ... x += 0.1 ... >>> x == 1.0 False This much I follow. The right way is to do it like this: >>> x = 0.0 >>> for i in range(1, 11): ... x = i*0.1 ... >>> x == 1.0 True But this I don't understand. Why would you use a loop when the final value is just the final multiplication. Since you know the final value in advance (you need it to create the loop!) why not just do the final multiplication directly: x = 10*0.1 I think I'm missing something? -- Alan Gauld 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] fourier transform (fwd)
"Una Murphy" wrote Got your info off the web . Was wondering if you tutor people in FFT ? I am looking for someone in the SF bay area. We are a tutor group for teaching the Python programming language. You probably want a math tutor group. If however you want to implement a FFT solution using Python we may be able to help, although specialised modules already exist which should do most of the work for you. HTH, -- Alan Gauld 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] Using the console module.
Python users, what's the best option for someone trying to emulate or use the curses module on the Windows platform? I've been fooling around with the console module: effbot.org/zone/console-handbook.htm But for the life of me, I can't figure out how to detect a KeyRelease. Could anyone share some insight, and maybe an example of how to code it? :( PS: I'm fairly new to programming. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help on reading a plain file of names
Hello there, I am new to python and I am trying to open a plain text file of names and to see the number of names that start with specific letters and display them in a bar graph. I have python version 3.2 and have the graphics.py package as well. If anybody out there knows how I could do this, with specific examples, please email me back, it would be much appreciated. LIke i said, i'm new to python, but very curious and willing to learn it. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] fourier transform (fwd)
Hi Jeff Got your info off the web . Was wondering if you tutor people in FFT ? I am looking for someone in the SF bay area. Thank you Una ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor