Re: [Tutor] Help with python 2.7
This is a mailing list, so the best way to get help is to send a request with code examples and most importantly what you have already tried. That being said, there are some smart people on here, much more experienced than I am on Python so I would say you can get help with any problem you may have. I have taken the MIT course you are talking about and it is quite challenging (perhaps a little more than it should be) and my oldest son at one point took the Microsoft MVA course on the subject of python and he said it was very good (surprisingly enough)..he is a Java programmer primarily and said that for someone with even average skill and ability, the MS course is actually great and easy to follow on. Good luck, and welcome. Mike On Mon, Oct 30, 2017, 7:24 PM Alchemywrote: > Hello, > > I am in the midst of a career change from renovations to computers. > I’m used to working conceptually and understand coding is that. > I am taking an online opencourseare classfrom MIT “Introduction to > computer science and programming”. > The class uses python 2.7, has video lectures and homework assignments > that are coding exercises. > Python seems like the root to everything in the computers possabilities > and I want to internalize it. > I’m stuck on the homework ,butmore importantly stuck on the concepts > behind the homework. > > Can your orginazation help? > > gratefully, > > Ian > > ___ > 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
Re: [Tutor] Help with python 2.7
On 30/10/17 21:02, Alchemy wrote: > I’m stuck on the homework ,butmore importantly stuck on the concepts behind > the homework. > > Can your orginazation help? Yes, we are happy to help with homework although we won't usually give you the full answer. We will make suggestions and are happy to review or comment on code. To make life easier: Always post any code in plain text (email messes up the formatting of html/rtf) And put it inline not as an attachment. Always post the full text of any error messages. Mention the OS and Python versions. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: 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] Help with python 2.7
Hello, I am in the midst of a career change from renovations to computers. I’m used to working conceptually and understand coding is that. I am taking an online opencourseare classfrom MIT “Introduction to computer science and programming”. The class uses python 2.7, has video lectures and homework assignments that are coding exercises. Python seems like the root to everything in the computers possabilities and I want to internalize it. I’m stuck on the homework ,butmore importantly stuck on the concepts behind the homework. Can your orginazation help? gratefully, Ian ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help With Python Tasks
On 05/09/17 19:25, Ruth Hardy wrote: > I was wondering if you can help me please with these computer science tasks We can help, but we won;t do them for you. > First Task > > Write code do the following things involving strings. Wherever possible, > you should try to incorporate functions/procedures, > > Print a list of 20 random numbers one after the other vertically on the > screen. There are (at least) two ways to do this. One very easy but laborious, the other much shorter and quicker. Do you know what they are? Can you print 20 numbers (forget random for now) on the screen? > Half way through, use a user input request to pause printing until > input is received. Do you know how to read user input? > Ask a user to enter two numbers, one after the other. This is slightly ambiguous, but I'd assume they mean you should ask for input twice. Do you know how to store user input into a variable? Do you know how to convert user input to a number? > Your code should validate that you receive numbers and > prompt the user appropriately. Do you know how to validate/check that the received input is a number? (there are several ways to do this, I'm not sure how they expect you to tackle it, it depends on what you've been taught so far) For the: > first number, use try-except to ensure you have a floating point number; OK, That answers my question. You can use try/except to check the number is valid... > place a comment in you code about how this works > second number, use .isnumeric() to check you have an integer; OK, They tell you what to do here. Personally I don;t like the isnumeric() technique but its what they want you to do so do it... > Use a forced type conversion to turn both numbers into floats, >divided one > by the other and print the answer to 2 d.p. Do you know how to print a number so it shows two dp? > You code should keep on asking for numbers until two have been received. OK, Lets just get it working for a single pair of numbers first. Done that? Good, so now wrap it in a loop. What kind of loop will work here? > Ask the user to input a true/false value and convert th> input to a Boolean > (hint: I don’t think you can do a forced > type conversion for this…) The hint is correct. How would you do it without a type conversion? > Second Task Let's leave this task to another email. See if you can answer the questions above. If you can you should be able to join the bits together to get the task completed. If not come back to us with specific issues sand we'll explain a bit more. Show us your code plus any error messages you get. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: 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] Help With Python Tasks
Dear Sir or Madam I was wondering if you can help me please with these computer science tasks as I don’t know where to start: First Task Write code do the following things involving strings. Wherever possible, you should try to incorporate functions/procedures, although they are not appropriate for all tasks. Print a list of 20 random numbers one after the other vertically on the screen. Half way through, use a user input request to pause printing until input is received. Ask a user to enter two numbers, one after the other. Your code should validate that you receive numbers and prompt the user appropriately. For the: first number, use try-except to ensure you have a floating point number; place a comment in you code about how this works second number, use .isnumeric() to check you have an integer; place a comment in your code to explain why this only works for integers Use a forced type conversion to turn both numbers into floats, divided one by the other and print the answer to 2 d.p. You code should keep on asking for numbers until two have been received. Ask the user to input a true/false value and convert the input to a Boolean (hint: I don’t think you can do a forced type conversion for this…) Second Task Write a menu system based on functions where the main program loop is only 2 lines long Write a simple calculator program based around a menu loop. You should be able to enter ‘number 1’ and ‘number 2’ which will be displayed on the screen every time the menu is redisplayed’; there should also be a clear screen function used to avoid the screen getting too cluttered. The calculator menu should allow the user to: enter values for ‘number 1’ and ‘number 2’ add ‘number 1’ and ‘number 2’ subtract ‘number 2’ from ‘number 1’ multiply ‘number 1’ and ‘number 2’ divide ‘number 1’ by ‘number 2’ exit cleanly You program must display an answer that the user can read after each calculation. I would appreciate your help so much as I need to have a finished copy of this code by tomorrow late morning ! Kind Regards Miss Hardy ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Python Queue
>I have below code but it is giving this error: >AttributeError: Queue instance has no attribute 'taskdone' >import threading >from Queue import Queue >def worker(q): >while True: > dataset = q.get() > print("q is taken out") > q.taskdone() Per documentation it is task_done (I suppose you are using python 3+) https://docs.python.org/3.5/library/queue.html This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Python Queue
On 26/11/16 09:07, anish singh wrote: > I have below code but it is giving this error: > AttributeError: Queue instance has no attribute 'taskdone' Please post the full error not just a summary. Also please post the actual code... > import threading > from Queue import Queue I get an import error here with no module named Queue. Which Queue module are you using? Or should it be spelled queue? > def worker(q): > while True: > dataset = q.get() > print("q is taken out") > q.taskdone() Assuming you meant the standard queue module then that should be q.task_done() When you get an attribute error it's worth trying dir() on the offending object: >>> from queue import Queue as Q >>> dir(Q) , task_done, >>> help(Q.task_done) ... HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: 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] Help with Python Queue
I was just writing to read a file using popen and wanted to use queue along with it. I have below code but it is giving this error: AttributeError: Queue instance has no attribute 'taskdone' import threading from Queue import Queue def worker(q): while True: dataset = q.get() print("q is taken out") q.taskdone() def create_data(q): print("Inside create data") output = [1, 2, 3] for i in output: print("Inside", i) print("queue is put") q.put(i) if __name__ == '__main__': q = Queue() t = threading.Thread(target=worker, args=(q,)) t.daemon = True t.start() create_data(q) q.join() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with python
On 19/04/16 10:13, Tim Golden wrote: > In any recent version of Windows (ie Vista & later) the most common way > to find a program is to press the "Start" button or the "Windows" key > and just start typing its name Interesting, I've been using Windows 10 since it came out and didn't know about that trick. I also haven't noticed it any of the PC mags I've read recently. > The same for the getting a command prompt up: press "Start/Windows" and > type "Command". I usually hit Windows->R and type cmd. So that's less useful for me. But thanks for the tip. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with python
On 19/04/2016 10:03, Alan Gauld wrote: However, for now, you probably want to use IDLE which should come with Python. (It is sometimes called Python GUI on Windows too.) You should find it under Python in your All Programs view. In any recent version of Windows (ie Vista & later) the most common way to find a program is to press the "Start" button or the "Windows" key and just start typing its name -- ie rather than actually navigating through a cascade of menus. (I think on other systems this is called a "Finder" or "Launcher" or something). In this particular case, pressing "Start/Windows" and typing "IDLE" gives -- in my case -- several options, including 3.4 64-bit etc. Hopefully, for the OP, there will be just one. The same for the getting a command prompt up: press "Start/Windows" and type "Command". Obviously it will depend on what's installed but for me the "Command Prompt" icon is the top of the resulting search list. Hope that helps people who are not used to (recent) Windows and are trying to advise novice users. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with python
On 19/04/16 02:20, Bereke via Tutor wrote: > Hello there: > > i am facing some problem with my python programming language which is > already installed in My laptop lenovo, 8.1 OS. I'm assuming that means Windows 8.1? > The existing language says "python 27 ". when i click on it, > it turns to "python or pythonw". I don't know what you mean when you say "click on it". Where are you clicking? The desktop? A menu? Windows explorer? And where does it say python or pythonw? > I can write on its dark surface, but it does not have tools like file, play, > edit,... It sounds like you are opening the Python interpreter in a command console. It will be helpful for you to learn how to use that console. There are several tutorials on the web if you search for "Windows command line". However, for now, you probably want to use IDLE which should come with Python. (It is sometimes called Python GUI on Windows too.) You should find it under Python in your All Programs view. Alternatively you can use Windows Explorer to search for the idle.bat file. Once you find it you can create a shortcut to your desktop or your start menu. 3 > what i need is, to be able to program on it, You can program using notepad and the console that you have but IDLE will be a better experience. On my Windows 10 box IDLE lives in this folder: C:\Python34\Lib\idlelib It should be similar for Windows 8.1 -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: 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] Help with python
Hello there: i am facing some problem with my python programming language which is already installed in My laptop lenovo, 8.1 OS. The existing language says "python 27 ". when i click on it, it turns to "python or pythonw". I can write on its dark surface, but it does not have tools like file, play, edit,...on the tool box. And i can not Copy past from it. when i down load a new 2.7.11 or 3.51 or any other version, it dawnloads only text, but what i need is, to be able to program on it, i.e to write on it and copy- paste my assignments. Could you give me some help please? Best regards Bere Sent from Samsung Mobile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Python code
On 29/02/16 17:31, Donald Woolfolk wrote: > Hello, > > I am new to Python 3.5 and I am writing code to get data > from a session api call and load that data into a csv file > or a MySQL database. That's great, we can help with that, but... > I am able to make the session call and also to connect to > the MySQL db, but I am not able to convert the result (JSON) data. We can't read minds. You need to show us your code. Show us your input and output data. Tell us where you are stuck. Include full error messages where appropriate. Tell us your OS and Python version too. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: 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] Help with Python code
Hello, I am new to Python 3.5 and I am writing code to get data from a session api call and load that data into a csv file or a MySQL database. I am able to make the session call and also to connect to the MySQL db, but I am not able to convert the result (JSON) data. I would like assistance with this if possible. Thanks, Don ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help Learn python - Step by Step
On Sat, May 9, 2015 7:08 PM CEST boB Stepp wrote: On Sat, May 9, 2015 at 3:23 AM, acolta andrycolt...@gmail.com wrote: Hi guys, I want to start coding in python. My background is Linux/Bash/Perl (begginner). My appreciate if somebody will recommend books/tutorials + exercises to practice. This question comes up quite frequently. If you have not done so already, try searching the Tutor archives. If you have a good bookstore nearby that is likely to carry programming-related books, you might just want to do some browsing and then look at reviews online. My local Barnes Noble (I'm in the USA.) always has a selection of Python books. And of course there are tons of online resources, including tutorials on Python's official site. As always, a search engine is your good friend. Also, Alan Gauld (Moderator for this list.) has a good one. Look for one of his emails; he always has a link to it in his signature area. I am learning myself, and, being old-fashioned (I suppose.), I tend to prefer hard-copy books. If you feel any degree of comfort writing Perl scripts and programming in general, then you might jump into something like Mark Summerfield's two book series, Programming in Python 3, 2nd ed. That book is goood, and even if you use Python 2 it barely matters that it's about Python 3. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help Learn python - Step by Step
Hi guys, I want to start coding in python. My background is Linux/Bash/Perl (begginner). My appreciate if somebody will recommend books/tutorials + exercises to practice. Thank you in advance, Andrei ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help Learn python - Step by Step
On Sat, May 9, 2015 at 3:23 AM, acolta andrycolt...@gmail.com wrote: Hi guys, I want to start coding in python. My background is Linux/Bash/Perl (begginner). My appreciate if somebody will recommend books/tutorials + exercises to practice. This question comes up quite frequently. If you have not done so already, try searching the Tutor archives. If you have a good bookstore nearby that is likely to carry programming-related books, you might just want to do some browsing and then look at reviews online. My local Barnes Noble (I'm in the USA.) always has a selection of Python books. And of course there are tons of online resources, including tutorials on Python's official site. As always, a search engine is your good friend. Also, Alan Gauld (Moderator for this list.) has a good one. Look for one of his emails; he always has a link to it in his signature area. I am learning myself, and, being old-fashioned (I suppose.), I tend to prefer hard-copy books. If you feel any degree of comfort writing Perl scripts and programming in general, then you might jump into something like Mark Summerfield's two book series, Programming in Python 3, 2nd ed. and Python in Practice. If you want to go really deep and cover pretty much everything, then Mark Lutz has two quite thick books, Learning Python, 5th ed. and Programming Program, 4th ed. One nice thing about the latter two books (Besides their completeness of language coverage.) is that Lutz points out the differences between Python 2 and 3 implementations, where appropriate. But if you are really a beginner beginner and did not make it very far in writing sophisticated Perl scripts, then you might enjoy something like Python Programming for the Absolute Beginner, 3rd ed. by Michael Dawson and More Python Programming for the Absolute Beginner by Jonathan S. Harbour. They both try to hold your interest and make things fun by designing only game-related programs. They both eventually use a form of the pygame module to get into graphics and audio. And for the stuff you already understand you can quickly skim through those portions. Finally, there are very knowledgeable people here willing to help you, but make certain you post your questions in a way that makes it easy for them to offer their help. Their time is very valuable and their efforts are entirely voluntary. So if you have not, please read the auto-generated email that covers how to post questions to this list, things like: Use plain text emails only; no top-posting (If you don't know what that means, search for it.); give your operating system and version of Python; think carefully about your question(s) and trim your code down to something that is self-contained and shows the exact problem you are experiencing; and, always post the *full* error report Python generates. HTH, -- boB ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help Learn python - Step by Step
On Sat, May 9, 2015 at 3:23 AM, acolta andrycolt...@gmail.com wrote: Hi guys, I want to start coding in python. My background is Linux/Bash/Perl (begginner). My appreciate if somebody will recommend books/tutorials + exercises to practice. I first cut my Python teeth using http://www.greenteapress.com/thinkpython/ and would highly recommend it as a starting point. The only reservation to be made is that it covers Python 2.x (probably 2.7) but not Python3 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help Learn python - Step by Step
On 09/05/15 09:23, acolta wrote: I want to start coding in python. My background is Linux/Bash/Perl (begginner). My appreciate if somebody will recommend books/tutorials + exercises to practice. If you are happy writing basic shell/perl scripts then you can probably jump straight into the official Python tutor. It usually comes with Python or you can fillow it online. It only takes a few hours to go through and gets an existing programmer up to speed easily. https://docs.python.org/3.4/tutorial/ If you are more of a beginner you can try the list of tutorials (including mine!) here: https://wiki.python.org/moin/BeginnersGuide/NonProgrammers They are all slightly different in flavour and you will probably find one that is to your taste. Most important make sure you match the tutorial version with your Python version since there are several differences between v2 and v3 that will catch you out otherwise. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help Learn python - Step by Step
Thanks for sharing, will try it. Cheers, Andrei On 9 May 2015 15:45, Nym City nymc...@yahoo.com wrote: I am on the same boat. I have tried using online sites like codeacademy and courses on courser but now I am starting with this new book called Automate The Boring Stuff with Python. So far so good. Thank you. On Saturday, May 9, 2015 8:41 AM, acolta andrycolt...@gmail.com wrote: Hi guys, I want to start coding in python. My background is Linux/Bash/Perl (begginner). My appreciate if somebody will recommend books/tutorials + exercises to practice. Thank you in advance, Andrei ___ 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
Re: [Tutor] Help Learn python - Step by Step
I am on the same boat. I have tried using online sites like codeacademy and courses on courser but now I am starting with this new book called Automate The Boring Stuff with Python. So far so good. Thank you. On Saturday, May 9, 2015 8:41 AM, acolta andrycolt...@gmail.com wrote: Hi guys, I want to start coding in python. My background is Linux/Bash/Perl (begginner). My appreciate if somebody will recommend books/tutorials + exercises to practice. Thank you in advance, Andrei ___ 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
Re: [Tutor] Help with python in MAC OS 10.6
On 27/02/15 02:16, Barbara Heliodora G. Rodrigues wrote: Dear tutor, I'd like to ask for help with an issue I have with python. My MAC is with OS 10-6.8, I'm not a MacOs expert but I know MacOS uses Python in some of its tools so do not mess with the standard version, you might break something. I can't install any new software that uses python, What the OS uses as Python should not necessarily impact what you use as Python. Usually its just a case of changing a link or creating an alias or environment variable. At the worst case you can edit the shebang line of your scripts. I tried to use some plot (matplotlib) routines that were working fine before, How are you running these scripts? Do you just double click an icon or do you use a commandline? If the latter what do you type? If the former somebody with a modern Mac will need to advise. Is there a way to force macports to install a 64bits version of python? Probably, but I don't know macports. I downloaded and installed the 3.4 and 3.1 myself, but still the computer only sees the version macports installed. Have you tried calling python3 instead of just python? That should find your Python 3.X version. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with python in MAC OS 10.6
On 27Feb2015 02:16, Barbara Heliodora G. Rodrigues barbara_...@yahoo.com.dmarc.invalid.br wrote: I'd like to ask for help with an issue I have with python. My MAC is with OS 10-6.8, darwin kernel, 64 bits. For some reason I updated macports and it automatically updated python to 2.7 with a 32 bits library, and it is giving me lots of trouble. I can't install any new software that uses python, and recently I tried to use some plot (matplotlib) routines that were working fine before, simply didn't work, the window with the plot didn't open.Is there a way to force macports to install a 64bits version of python? Since I use MacPorts and Alan doesn't I'll chip in... First up, you're talking about the MacPorts pythn (in /opt/local) not the system Python (in /usr). This page: http://stackoverflow.com/questions/2111283/how-to-build-64-bit-python-on-os-x-10-6-only-64-bit-no-universal-nonsense seems to offer useful advice on getting MacPorts to install your preferred variant on Python. Next, re this: I downloaded and installed the 3.4 and 3.1 myself, but still the computer only sees the version macports installed. You need to clarify what this statement means, probably with examples of how you are invoking your python programs, and the output of which python. Your Mac should (now) have multiple Pythons installed: /usr/bin/python Supplied with MacOSX, the system Python. Probably 64-bit python. As the cited web page above says, run: file /usr/bin/python to see what architecture it is. You can do that for any of the other executables too to check how they were built. /opt/local/bin/python The MacPorts python (python 2 by default). It should like you need to reinstall this with the right variants settings to get it to be 64-bit. Your personally built Pythons. Regarding the last, please outline what options you used to build these. It is very important to build/install with a suitable --prefix Configure option to put them in the right place: not a specific place, but a place _not_ conflicting with the OSX or MacPorts pythons, for example /usr/local/python-2.7.7 (adjust to suit). It is normal to add some symlinks in /usr/local/bin for python, python2 etc pointing at your preferred executables. Next, _how_ are you installing extra packages like matplotlib etc? I would advocate using MacPorts to install these if available; that leaves the arrangements in the hands of MacPorts and keeps things simple for you. Otherwise, I would next suggest learning to use virtualenv to make a specific python environment for you work. This is easier than it sounds. The virtualenv command prepares a direct of your choice (eg $HOME/venv-2.7.7, to invent a name) which contains python and pip executables in the bin subdirectory which are crafted to automatically install and use packages entirely within the virtualenv directory, avoiding conflicts with other systems like OSX or MacPorts. This is great for experimentation of maintaining special setups of your own. You can base the virtualenv of any of the installed Pythons (OSX, MacPorts, whatever), to get the installed libraries for free. Please respond with further information and we can proceed from there. Cheers, Cameron Simpson c...@zip.com.au To have no errors Would be life without meaning No struggle, no joy - Haiku Error Messages http://www.salonmagazine.com/21st/chal/1998/02/10chal2.html ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with python in MAC OS 10.6
Dear tutor, I'd like to ask for help with an issue I have with python. My MAC is with OS 10-6.8, darwin kernel, 64 bits. For some reason I updated macports and it automatically updated python to 2.7 with a 32 bits library, and it is giving me lots of trouble. I can't install any new software that uses python, and recently I tried to use some plot (matplotlib) routines that were working fine before, simply didn't work, the window with the plot didn't open.Is there a way to force macports to install a 64bits version of python?I downloaded and installed the 3.4 and 3.1 myself, but still the computer only sees the version macports installed.Thank you!Regards, Bárbara ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help on Python drop-down list options
Hello All, I need help on the following: I have a created a project from a csv file to calculate the mean and standard deviation. However, I would like to create a drop-down list and display the mean and standard deviation? Is there a module for that? Thank you, Tammy ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help on Python drop-down list options
What is the user interface that your program is using, currently? IE: QT, GTK, Tkinter, Curses, Kivy, Pygame, Or None? What is the target system on which your program runs? How are you currently viewing the mean and standard deviation results? What version of Python are you using and what is your OS? On 12/31/2014 08:49 AM, Tammy Miller wrote: Hello All, I need help on the following: I have a created a project from a csv file to calculate the mean and standard deviation. However, I would like to create a drop-down list and display the mean and standard deviation? Is there a module for that? Thank you, Tammy ___ 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
Re: [Tutor] Help on Python drop-down list options
On 31/12/14 13:49, Tammy Miller wrote: I need help on the following: I have a created a project from a csv file to calculate the mean and standard deviation. I assume that means you read the data from the CSV file and display the stats? However, I would like to create a drop-down list and display the mean and standard deviation? I assume you mean you want to create a GUI that has a drop down list containing data and you want to display the stats based on the list contents? If so you need to decide what kind of UI you want to use. Your choices are: 1) CLI using curses (Not on windows) 2) Web UI based on HTML/Javascript 3) Desktop GUI using Tkinter/WxPython/PyGTK (or some other toolkit) And once you decide your option you need to design what the UI looks like - how does the output appear? Is it in a label? a text widget? a pop-up dialog? Is there a module for that? Yes, for all of the above. Option 1 uses the curses module Option 2 uses standard HTML linked to a CGI(standard library) or a web framework(several third-party options) Option 3: the standard library includes Tkinter, the others are third-party downloads. We can't help much until you make the choices above. It will help if you tell us which python version and which OS you use. And once you choose an option which tookkit you want to go with (or at least which option and we can advise on toolkits based on your experience and your UI visual design) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: 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] Help with Python
Hello, I am student trying to fugure out why when I enter any number it says error. It's only suppose to do that if it's out the 1-10 range. Please help. Thank you. number = input('Enter a number between 1 and 10: ') while number 1 or number 10: print 'Please enter a number between 1 and 10' number = input('Enter a number between 1 and 10: ') number = input('Enter a number between 1 and 10: ') while number 1 or number 10: print 'Error' number = input('Enter a number between 1 and 10: ') endProgram = raw_input('Do you want to end program? (Enter no or yes): ') while not (endProgram == 'yes' or endProgram == 'no'): print 'Please enter a yes or no' endProgram = raw_input('Do you want to end program? (Enter no to process a new set of scores): ') ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Python
On 16/05/14 02:58, Glen Chan wrote: Hello, I am student trying to fugure out why when I enter any number it says error. Because that's what you programmed it to do. Almost. If you enter 1 or 10 you won't get an error. Look at your logic: number = input('Enter a number between 1 and 10: ') while number 1 or number 10: print 'Please enter a number between 1 and 10' number = input('Enter a number between 1 and 10: ') number = input('Enter a number between 1 and 10: ') while number 1 or number 10: print 'Error' number = input('Enter a number between 1 and 10: ') If the first number you enter is say 7. It skips the first while loop and asks for another number. If you enter 7 again It then goes into the second while loop and reports an error. The only numbers which don't fall into one of the two loops are 1 and 10. BTW It's bad practice to use input() in Python v2 becauise it has security issues. Instead use raw_input() and convert to an int() or float() explicitly. while not (endProgram == 'yes' or endProgram == 'no'): print 'Please enter a yes or no' There is a bug here too since you don't provide a way for the user to enter a new number. It will loop forever. HTH -- 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
Re: [Tutor] Help with Python
Hi Glen, and welcome! My responses below. On Thu, May 15, 2014 at 09:58:07PM -0400, Glen Chan wrote: Hello, I am student trying to fugure out why when I enter any number it says error. It's only suppose to do that if it's out the 1-10 range. Please help. Thank you. You've made an mistake in your logic below. You print an error for *every* number: number = input('Enter a number between 1 and 10: ') while number 1 or number 10: print 'Please enter a number between 1 and 10' number = input('Enter a number between 1 and 10: ') This part is okay. You check that if number is out of range, and if it is, it prints a message. Check for yourself: Suppose I choose 5. Is 5 less than 1? No. Is it larger than 10? No. So the while loop immediately ends, and I move on. So at this stage, you have now successfully asked the user for a number between 1 and 10. But here you make the mistake: number = input('Enter a number between 1 and 10: ') Hmmm. You've already asked the user for a number. But then you ignore it, and ask for another one. But even that's not really the mistake: while number 1 or number 10: print 'Error' number = input('Enter a number between 1 and 10: ') And this is where you get the logic backwards. This while loop runs forever, or until you manually cancel it. Check for yourself: Suppose I choose 5. Is 5 larger than 1? Yes. So the while loop continues, and 'Error' is printed. Suppose I choose 0. Is 0 larger than 1? No. Is 0 less than 10? Yes. So again, the while loop continues, and 'Error' is printed. Are there *any* numbers *smaller* than 1 AND *larger* than 10 at the same time? No, of course not. So the while loop condition is always true, and the while loop will always run no matter what number I choose. This second while loop has the logic backwards. You should compare this one, the faulty one, with the first one, the correct one. Can you see the difference? A couple of other comments about your code: * In a few places, you use input, but in other places, you use raw_input. You should never use input. It was a mistake, and has been removed from newer versions of Python. Instead, you should write int(raw_input(Enter a number...)). * You check that number is in range like this: number 1 or number 10 There's an easier way: 1 = number = 10 which is not only less typing, but makes it more obvious what you are trying to do. You want number to be in the range 1 through 10 inclusive. That makes it harder to screw up the logic: 1 = number = 10 # Wrong! What do you mean, 1 is BIGGER than number, which is bigger than 10? That's impossible! -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Python
Hi This will solve your purpose: Yes we can write in better way also : -- #The Dice Game #add libraries needed import random #the main function def main(): print #initialize variables playerOne = 'No Name' playerTwo = 'No Name' endProgram =no #call to inputNames playerOne, playerTwo = inputNames(playerOne, playerTwo) #while loop to run program again while endProgram == 'no': #call to rollDice winnersName = rollDice(playerOne, playerTwo) #call to displayInfo print Winner is , winnersName endProgram = raw_input('Do you want to end program? (Enter yes or no): ') #this function gets the players names def inputNames(playerOne, playerTwo): playerOne = raw_input(Enter Name) playerTwo = raw_input(Enter Name) return playerOne, playerTwo #this function will get the random values def rollDice(playerOne, playerTwo): p1number = random.randint(1, 6) p2number = random.randint(1, 6) #this function displays the winner if p1number == p2number: winnerName = TIE elif p1number p2number: winnerName = playerOne else: winnerName = playerTwo return winnerName if __name__ == __main__: # calls main main() On Sun, May 11, 2014 at 8:46 AM, Glen Chan gchan...@msn.com wrote: Hello, I am a student trying to figure out Python. I am getting errors that I don't know how to fix. What do you do after you get the error message and something is highlighted? Does that have to be deleted? Anyway, here is what I mean... # The Dice Game #add libraries needed import random #the main function def main(): print #initialize variables playerOne = 'No Name' playerTwo = 'No Name' #call to inputNames playerOne, playerTwo = inputNames(playerOne, playerTwo) #while loop to run program again while endProgram == 'no': #initialize variables winnersName = 'NO NAME' p1number = 0 p2number = 0 #call to rollDice winnerName = rollDice(p1number, p2number, playerOne, playerTwo, winnerName) #call to displayInfo winnerName endProgram = raw_input('Do you want to end program? (Enter yes or no): ') #this function gets the players names def inputNames(playerOne, playerTwo): playerOne = raw_input(Enter Name) playerTwo = raw_input(Enter Name) return playerOne, playerTwo #this function will get the random values def rollDice(p1numer, p2numer, playerOne, playerTwo, winnerName): p1number = random.randint(1, 6) p1number = random.randint(1, 6) #this function displays the winner if p1number == p2number: winnerName = TIE elif p1number p2number: winnerName = playerOne else: winnerName = playerTwo return winnerName # calls main main() ___ 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
[Tutor] Help with Python
Hello, I am a student trying to figure out Python. I am getting errors that I don't know how to fix. What do you do after you get the error message and something is highlighted? Does that have to be deleted? Anyway, here is what I mean... # The Dice Game #add libraries needed import random #the main function def main(): print #initialize variables playerOne = 'No Name' playerTwo = 'No Name' #call to inputNames playerOne, playerTwo = inputNames(playerOne, playerTwo) #while loop to run program again while endProgram == 'no': #initialize variables winnersName = 'NO NAME' p1number = 0 p2number = 0 #call to rollDice winnerName = rollDice(p1number, p2number, playerOne, playerTwo, winnerName) #call to displayInfo winnerName endProgram = raw_input('Do you want to end program? (Enter yes or no): ') #this function gets the players names def inputNames(playerOne, playerTwo): playerOne = raw_input(Enter Name) playerTwo = raw_input(Enter Name) return playerOne, playerTwo #this function will get the random values def rollDice(p1numer, p2numer, playerOne, playerTwo, winnerName): p1number = random.randint(1, 6) p1number = random.randint(1, 6) #this function displays the winner if p1number == p2number: winnerName = TIE elif p1number p2number: winnerName = playerOne else: winnerName = playerTwo return winnerName # calls main main() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Python
Hey Glen, include the error you are getting. It will make answering your question easier. How are you running this program, in an IDE? On Sat, May 10, 2014 at 11:16 PM, Glen Chan gchan...@msn.com wrote: Hello, I am a student trying to figure out Python. I am getting errors that I don't know how to fix. What do you do after you get the error message and something is highlighted? Does that have to be deleted? Anyway, here is what I mean... # The Dice Game #add libraries needed import random #the main function def main(): print #initialize variables playerOne = 'No Name' playerTwo = 'No Name' #call to inputNames playerOne, playerTwo = inputNames(playerOne, playerTwo) #while loop to run program again while endProgram == 'no': #initialize variables winnersName = 'NO NAME' p1number = 0 p2number = 0 #call to rollDice winnerName = rollDice(p1number, p2number, playerOne, playerTwo, winnerName) #call to displayInfo winnerName endProgram = raw_input('Do you want to end program? (Enter yes or no): ') #this function gets the players names def inputNames(playerOne, playerTwo): playerOne = raw_input(Enter Name) playerTwo = raw_input(Enter Name) return playerOne, playerTwo #this function will get the random values def rollDice(p1numer, p2numer, playerOne, playerTwo, winnerName): p1number = random.randint(1, 6) p1number = random.randint(1, 6) #this function displays the winner if p1number == p2number: winnerName = TIE elif p1number p2number: winnerName = playerOne else: winnerName = playerTwo return winnerName # calls main main() ___ 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
Re: [Tutor] Help with Python
On 11/05/14 04:16, Glen Chan wrote: Hello, I am a student trying to figure out Python. I am getting errors that I don't know how to fix. What do you do after you get the error message and something is highlighted? Does that have to be deleted? The error doesn't need to be deleted because it appears in the interpreter, not in your code. However,... # The Dice Game Are you trying to type the whole program into the interactive Python shell? If so that's the wrong approach. The prompt is only intended for entering a few lines to experiment and find out how things work. You should create a new text file and write the code into that. You can then run the file in the interpreter. If you are using an IDE (such as IDLE) that usually means you use the File-New menu and an editor window will appear. There will then be a Run menu somewhere (in IDLE its Run-Run Module) to run the program. If you are using IDLE take a look at Danny's tutorial here: http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html As to your error please copy the en tire error message and send it to us, otherwise we have to guess what the problem is... HTH -- 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
Re: [Tutor] Help with Python
On 05/10/2014 11:16 PM, Glen Chan wrote: Hello, I am a student trying to figure out Python. I am getting errors that I don't know how to fix. What do you do after you get the error message and something is highlighted? Does that have to be deleted? Anyway, here is what I mean... def main(): print #initialize variables playerOne = 'No Name' playerTwo = 'No Name' #call to inputNames playerOne, playerTwo = inputNames(playerOne, playerTwo) #while loop to run program again while endProgram == 'no': #initialize variables winnersName = 'NO NAME' p1number = 0 p2number = 0 #call to rollDice winnerName = rollDice(p1number, p2number, playerOne, playerTwo, winnerName) #call to displayInfo winnerName endProgram = raw_input('Do you want to end program? (Enter yes or no): ') When posting a question, you should always specify the Python version and OS, though it probably doesn't matter here. As others have said, please paste the exact error message. This is a text mailing list, so any highlighting you may have tried to include is lost on most of us. Please post in a text message, not html, as many things can go wrong in the re-interpretation, especially in any source code. I pasted your code into a text editor, saved the file, and ran it a terminal window in Python 2.7 under Linux, davea@think2:~/temppython$ python glen.py File glen.py, line 25 endProgram = raw_input('Do you want to end program? (Enter yes or no): ') ^ IndentationError: unexpected indent davea@think2:~/temppython$ As you can see the callstack shows the line that has a problem, and shows s a specific error message. The problem is that you indented a line improperly. You only add to the indentation within a function, an if/else statement statement block, class, with clause, etc. Ordinary statemdents have to line up with the ones before, not counting comments. If you line up the endProgram line with the previous winnername line, this particular error will go away. But you have others. I notice you mix spaces and tabs for indentation, which is dangerously confusing. You should stick to one or the other, and I prefer spaces. I configured my text editor (emacs) to turn any tabs into 4 spaces, so that I won't get into trouble. in some places you only indent by one space. That's hard to read and you can wind up with problems from that. Better to stick with 4, though some people seem to prefer 2. Next problem is: davea@think2:~/temppython$ python glen.py File glen.py, line 44 elif p1number p2number: ^ IndentationError: unindent does not match any outer indentation level This error is because the elif clause does not line up with the if clause. But a bigger problem in that portion of code is that you're apparently starting a new function, but never define it. No def line follows the comment: #this function displays the winner If you add that def xxx(): line, and indent the if, then the elif will line up as expected. After fixing that, the next error is: Traceback (most recent call last): File glen.py, line 51, in module main() File glen.py, line 15, in main while endProgram == 'no': UnboundLocalError: local variable 'endProgram' referenced before assignment That comes because you have a while statement that refers to the variable endProgram, which has not been yet bound to a value. You need endProgram = no before that if statement. In each of these cases, the error message tells you pretty closely what's wrong, and where. You will need to learn to read the error messages, the tracebacks. Your next problem is one of program logic, and I leave it to you. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with python
I'm writing a program to calculate totals and change for a menu, and I'm having a few issues. If you could help me, it would be greatly appreciated. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with python
On 02/12/2013 22:33, Blake wrote: I'm writing a program to calculate totals and change for a menu, and I'm having a few issues. If you could help me, it would be greatly appreciated. A little more data would help :) Some code, the OS and Python versions and the precise nature of the issues would be a good starting point. If you've not already read it here's a good starting point for how to put your question(s) together http://sscce.org/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with python
On Mon, Dec 02, 2013 at 04:33:27PM -0600, Blake wrote: I'm writing a program to calculate totals and change for a menu, and I'm having a few issues. If you could help me, it would be greatly appreciated. Would you like us to guess what issues you are having? Let me look into my crystal ball... I see... a cat walking on your keyboard... Do you have a cat? Keep it off your keyboard, and your programs will be much better. No no, don't thank me, it's all part of the service! *wink* -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with Python in ArcGIS 10.1!
Hi, I have a command line to spread geoprocessing operations across multiple processes to speed up performance. However, I do not know how to import the command line (or at least import it properly) in Python 2.7.2. Here's the script example given on ArcGIS 10.1 Help: import arcpy # Use half of the cores on the machine. arcpy.env.parallelProcessingFactor = 50% I tried typing it into the command line but nothing happened. Instructions would be much appreciated!!! Teri A. Jacobs Geography Fellow Surveillance Branch/DSHEFS/NIOSH/CDC 513-841-4338 w...@cdc.govmailto:w...@cdc.gov ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Python in ArcGIS 10.1!
On 6/17/2013 10:26 AM, Jacobs, Teri (CDC/NIOSH/DSHEFS) (CTR) wrote: Hi, Hi - welcome to the tutor list. Be aware that we are a few volunteers. Your question is one very long line. Please in future ensure it is wrapped so we don't have to scroll. I have wrapped it here. I have a command line What is a command line? to spread geoprocessing operations across multiple processes to speed up performance. However, I do not know how to import the command line (or at least import it properly) in Python 2.7.2. Here's the script example given on ArcGIS 10.1 Help: import arcpy # Use half of the cores on the machine. arcpy.env.parallelProcessingFactor = 50% I tried typing it What is it. You show 3 lines of code above. Do you mean all 3 lines? into the command line What is the command line? Do you mean Command Prompt or Python shell? but nothing happened. What did you expect? Did you hit enter after each line? Did the cursor move to the next line? Did you get another prompt? What did the prompt look like? I think you get the idea - you need to tell us more, since we did not watch you try the above. -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help on python
is it possible to reorder a sentence in the form of SVO (Subject Verb Object) into the form of SOV (Subject Object Verb) by using a python program? if so, how? regards, ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help on python
On 15/04/2013 09:54, Jabesa Daba wrote: is it possible to reorder a sentence in the form of SVO (Subject Verb Object) into the form of SOV (Subject Object Verb) by using a python program? if so, how? regards, Yes. By writing code. You could have answered your own question by typing something like python natural language processing into your favourite search engine. -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help on python
On 15/04/13 09:54, Jabesa Daba wrote: is it possible to reorder a sentence in the form of SVO (Subject Verb Object) into the form of SOV (Subject Object Verb) by using a python program? if so, how? Python is a general purpose programming language so yes, you can program it to do any computational task. How much work is involved depends on how well you can define the algorithm and whether somebody else has already implemented it for you in Python. In your case you need to consider which language you are processing and what the grammatical rules are (what is a word? How do you identify a subject, object and verb? What are the separator rules and do you need to consider changes of endings etc when you change order? etc) Just how sophisticated does it need to be?) There are several libraries that can help ranging from general purpose text processing and parsers to natural language tookits. Whatever you use you will still need a fair amount of effort to get it working. Google (or any other search engine!) is your friend. -- 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] Help on python
For example, see: http://nltk.org. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help- Regarding python
On 5 February 2013 05:08, eryksun eryk...@gmail.com wrote: On Mon, Feb 4, 2013 at 7:21 PM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: eigenvalues, eigenvectors = np.linalg.eig(C) First sort by eigenvalue magnitude: idx = np.argsort(eigenvalues)[::-1] print idx [ 0 1 2 3 8 10 11 12 14 22 20 21 18 19 23 24 17 16 15 13 9 7 5 6 4] eigenvalues = eigenvalues[idx] eigenvectors = eigenvectors[:, idx] # 2D PCA - get the two eigenvectors with the largest eigenvalues v1, v2 = eigenvectors[:,:2].T Thanks. I thought that eig already sorted them. The doc claims says that the values are not necessarily ordered but when I run it they are in descending order of absolute value. Also I should have used eigh since the covariance matrix is Hermitian (eigh seems to give the eigenvalues in ascending order). Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help- Regarding python
On 04/02/13 06:24, Gayathri S wrote: Hi All! If i have data set like this means... 3626,5000,2918,5000,2353,2334,2642,1730,1687,1695,1717,1744,593,502,493,504,449,431,444,444,429,10 ... 458,5022,3640,3644,5000,2922,5000,2346,2321,2628,1688,1666,1674,1696,744,590,496. How to do PCA on this data? if it is in array how to do that? and also how to use princomp() in PCA? No idea. I don't know what pca or princomp are. It looks like they might be numpy or pylab functions in which case you probably will get better results posting on a forum for those modules. This list is for learning the core language and standard library. Having said that it looks like you could use some time learning the basics before delving into numpy etc. comments below... from numpy import mean,cov,double,cumsum,dot,linalg,array,rank from pylab import plot,subplot,axis,stem,show,figure A = array([ [2.4,0.7,2.9,2.2,3.0,2.7,1.6,1.1,1.6,0.9], [2.5,0.5,2.2,1.9,3.1,2.3,2,1,1.5,1.1] ]) M = (A-mean(A.T,axis=1)).T[latent,coeff] = linalg.eig(cov(M)) score = dot(coeff.T,M) return coeff,score,latent You have a return that is not inside a function. That makes no sense and in fact I get a syntax error so presumably you haven't actually tried running this code. princomp(A): This calls princomp() but does nothing with the return values coeff, score, latent = princomp(A.T) This calls princomp() and stores 3 return values. Its unusual for a function to have such different semantics. Which is correct? figure() subplot(121) Again calling functions without storing values. It may be valid but looks unlikely... m = mean(A,axis=1) plot([0, -coeff[0,0]*2]+m[0], [0, -coeff[0,1]*2]+m[1],'--k') plot([0, coeff[1,0]*2]+m[0], [0, coeff[1,1]*2]+m[1],'--k') plot(A[0,:],A[1,:],'ob') # the data axis('equal') subplot(122) plot(score[0,:],score[1,:],'*g') axis('equal') plt.show() Here you use plt but plt is not defined anywhere in your program. I think you need to go back to Python basics and learn how to write basic code before trying to use the more exotic modules. -- 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] Help- Regarding python
On 04/02/13 17:24, Gayathri S wrote: Hi All! If i have data set like this means... 3626,5000,2918,5000,2353,2334,2642,[...],496. No need to dump your entire data set on us. Just a few representative values will do. How to do PCA on this data? if it is in array how to do that? and also how to use princomp() in PCA? What's PCA? What's princomp? Shall i use the following code for doing PCA on given input? could you tell me? Have you tried it? What happens? This is a list for people learning Python the programming language. We are not experts on numpy, which is a specialist package for scientific use. We are not statisticians either. You can probably assume that most of us know what standard deviation is. Anything more complicated than that, you should ask on a specialist numpy mailing list. Good luck! -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help- Regarding python
How to do PCA on this data? if it is in array how to do that? and also how to use princomp() in PCA? Principal component analysis, http://en.wikipedia.org/wiki/Principal_component_analysis may not be built in. Do you know for sure that it is? According to this blog entry, you can do it in numpy by coding the algorithm: http://glowingpython.blogspot.com/2011/07/principal-component-analysis-with-numpy.html If you use Google and search for the term Principal component analysis Python, you should see several implementations of modules that provide that algorithm. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help- Regarding python
On 4 February 2013 06:24, Gayathri S gayathri.s...@gmail.com wrote: Hi All! If i have data set like this means... 3626,5000,2918,5000,2353,2334,2642,1730,1687,1695,1717,1744,593,502,493,504,449,431,444,444,429,10 438,498,3626,3629,5000,2918,5000,2640,2334,2639,1696,1687,1695,1717,1744,592,502,493,504,449,431,444,441,429,10 439,498,3626,3629,5000,2918,5000,2633,2334,2645,1705,1686,1694,1719,1744,589,502,493,504,446,431,444,444,430,10 440,5000,3627,3628,5000,2919,3028,2346,2330,2638,1727,1684,1692,1714,1745,588,501,492,504,451,433,446,444,432,10 444,5021,3631,3634,5000,2919,5000,2626,2327,2638,1698,1680,1688,1709,1740,595,500,491,503,453,436,448,444,436,10 451,5025,3635,3639,5000,2920,3027,2620,2323,2632,1706,1673,1681,1703,753,595,499,491,502,457,440,453,454,442,20 458,5022,3640,3644,5000,2922,5000,2346,2321,2628,1688,1666,1674,1696,744,590,496. PCA only makes sense for multivariate data: your data should be a set of vectors *all of the same length*. I'll assume that you were just being lazy when you posted it and that you didn't bother to copy the first and last lines properly... [snip] Shall i use the following code for doing PCA on given input? could you tell me? This code you posted is all screwed up. It will give you errors if you try to run it. Also I don't really know what you mean by doing PCA. The code below transforms your data into PCA space and plots a 2D scatter plot using the first two principal components. #!/usr/bin/env python import numpy as np from matplotlib import pyplot as plt data = np.array([ [438,498,3626,3629,5000,2918,5000,2640,2334,2639,1696,1687,1695,1717,1744,592,502,493,504,449,431,444,441,429,10], [439,498,3626,3629,5000,2918,5000,2633,2334,2645,1705,1686,1694,1719,1744,589,502,493,504,446,431,444,444,430,10], [440,5000,3627,3628,5000,2919,3028,2346,2330,2638,1727,1684,1692,1714,1745,588,501,492,504,451,433,446,444,432,10], [444,5021,3631,3634,5000,2919,5000,2626,2327,2638,1698,1680,1688,1709,1740,595,500,491,503,453,436,448,444,436,10], [451,5025,3635,3639,5000,2920,3027,2620,2323,2632,1706,1673,1681,1703,753,595,499,491,502,457,440,453,454,442,20], ]) # Compute the eigenvalues and vectors of the covariance matrix C = np.cov(data.T) eigenvalues, eigenvectors = np.linalg.eig(C) # 2D PCA - get the two eigenvectors with the largest eigenvalues v1, v2 = eigenvectors[:,:2].T # Project the data onto the two principal components data_pc1 = [np.dot(v1, d) for d in data] data_pc2 = [np.dot(v2, d) for d in data] # Scatter plot in PCA space fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.plot(data_pc1, data_pc2, 'x') ax.set_xlabel(r'$PC_1$') ax.set_ylabel(r'$PC_2$') ax.legend(['data']) plt.show() Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help- Regarding python
On Mon, Feb 4, 2013 at 7:21 PM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: eigenvalues, eigenvectors = np.linalg.eig(C) First sort by eigenvalue magnitude: idx = np.argsort(eigenvalues)[::-1] print idx [ 0 1 2 3 8 10 11 12 14 22 20 21 18 19 23 24 17 16 15 13 9 7 5 6 4] eigenvalues = eigenvalues[idx] eigenvectors = eigenvectors[:, idx] # 2D PCA - get the two eigenvectors with the largest eigenvalues v1, v2 = eigenvectors[:,:2].T ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help- Regarding python
Hi All! If i have data set like this means... 3626,5000,2918,5000,2353,2334,2642,1730,1687,1695,1717,1744,593,502,493,504,449,431,444,444,429,10 438,498,3626,3629,5000,2918,5000,2640,2334,2639,1696,1687,1695,1717,1744,592,502,493,504,449,431,444,441,429,10 439,498,3626,3629,5000,2918,5000,2633,2334,2645,1705,1686,1694,1719,1744,589,502,493,504,446,431,444,444,430,10 440,5000,3627,3628,5000,2919,3028,2346,2330,2638,1727,1684,1692,1714,1745,588,501,492,504,451,433,446,444,432,10 444,5021,3631,3634,5000,2919,5000,2626,2327,2638,1698,1680,1688,1709,1740,595,500,491,503,453,436,448,444,436,10 451,5025,3635,3639,5000,2920,3027,2620,2323,2632,1706,1673,1681,1703,753,595,499,491,502,457,440,453,454,442,20 458,5022,3640,3644,5000,2922,5000,2346,2321,2628,1688,1666,1674,1696,744,590,496. How to do PCA on this data? if it is in array how to do that? and also how to use princomp() in PCA? Shall i use the following code for doing PCA on given input? could you tell me? from numpy import mean,cov,double,cumsum,dot,linalg,array,rank from pylab import plot,subplot,axis,stem,show,figure A = array([ [2.4,0.7,2.9,2.2,3.0,2.7,1.6,1.1,1.6,0.9], [2.5,0.5,2.2,1.9,3.1,2.3,2,1,1.5,1.1] ]) M = (A-mean(A.T,axis=1)).T[latent,coeff] = linalg.eig(cov(M)) score = dot(coeff.T,M) return coeff,score,latent princomp(A): coeff, score, latent = princomp(A.T) figure() subplot(121) m = mean(A,axis=1) plot([0, -coeff[0,0]*2]+m[0], [0, -coeff[0,1]*2]+m[1],'--k') plot([0, coeff[1,0]*2]+m[0], [0, coeff[1,1]*2]+m[1],'--k') plot(A[0,:],A[1,:],'ob') # the data axis('equal') subplot(122) plot(score[0,:],score[1,:],'*g') axis('equal') plt.show() Thanks! Regards, Gayathri. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP-Regarding python
On 1/30/2013 1:51 AM, Gayathri S wrote: I am sorry that you chose to ignore my request to start a new email with a relevant subject. Please next time do so. The easier you make it for us to help you the more likely we will want to help. -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] HELP-Regarding python
Hi All! I don't know how to read text file in python. If the data values are stored in a text file format, for example(1,30,60,90,120...200) means what i would do for reading it in python. could you just explain it. Thanks! Keep Smiling.[?] Regards Gayu[?] 335.png___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP-Regarding python
On 01/30/2013 01:51 AM, Gayathri S wrote: Hi All! I don't know how to read text file in python. If the data values are stored in a text file format, for example(1,30,60,90,120...200) means what i would do for reading it in python. could you just explain it. infile = open(filename, rt)will open a text file line = infile.readline()will read one line from it, as a str After that, you can parse it anyway you like. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP-Regarding python
A safer approach would be - with open(filepath, mode as filehandle: indent//operation with the file. This way, you do not have to remember to close the file explicitly. On Wed, Jan 30, 2013 at 12:27 PM, Dave Angel da...@davea.name wrote: On 01/30/2013 01:51 AM, Gayathri S wrote: Hi All! I don't know how to read text file in python. If the data values are stored in a text file format, for example(1,30,60,90,120...200) means what i would do for reading it in python. could you just explain it. infile = open(filename, rt)will open a text file line = infile.readline()will read one line from it, as a str After that, you can parse it anyway you like. -- DaveA __**_ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/**mailman/listinfo/tutorhttp://mail.python.org/mailman/listinfo/tutor -- http://spawgi.wordpress.com We can do it and do it better. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP-Regarding python
missed a parenthesis, it should look like - with open(filepath, mode) as filehandle: indent//operation with the file. On Wed, Jan 30, 2013 at 12:31 PM, spa...@gmail.com wrote: A safer approach would be - with open(filepath, mode as filehandle: indent//operation with the file. This way, you do not have to remember to close the file explicitly. On Wed, Jan 30, 2013 at 12:27 PM, Dave Angel da...@davea.name wrote: On 01/30/2013 01:51 AM, Gayathri S wrote: Hi All! I don't know how to read text file in python. If the data values are stored in a text file format, for example(1,30,60,90,120...200) means what i would do for reading it in python. could you just explain it. infile = open(filename, rt)will open a text file line = infile.readline()will read one line from it, as a str After that, you can parse it anyway you like. -- DaveA __**_ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/**mailman/listinfo/tutorhttp://mail.python.org/mailman/listinfo/tutor -- http://spawgi.wordpress.com We can do it and do it better. -- http://spawgi.wordpress.com We can do it and do it better. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help for Python Beginner with extracting and manipulating data from thousands of ASCII files
Hi Cecilia, I'm sending this again as the first message was sent only to you (I hadn't realised that your own message was sent only to me as well). If you want to reply please reply-all to this message. On 1 October 2012 17:42, Cecilia Chavana-Bryant cecilia.chav...@gmail.com wrote: On Mon, Oct 1, 2012 at 11:02 AM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On Sep 30, 2012 11:10 PM, Cecilia Chavana-Bryant cecilia.chav...@gmail.com wrote: fileDate = data[6][16:26] # location of the creation date on the data files What format does fileDate have? I guess it's a string of text from the file. If you can convert it to a datetime (or date) object it will be easy to compare with the dates as required for your calibration file. Can you show us how it looks e.g. '12-Nov-2012' or '12/11/12' or something else? Date is in the following format: dd/mm/ The standard way to work with dates is to turn the date strings into Python datetime objects. You can read about those here: http://docs.python.org/library/datetime.html datetime objects can be create directly: from datetime import datetime start_date = datetime(year=2012, month=11, day=3) print start_date 2012-11-03 00:00:00 You can also create them from a string: datestring = '10/11/2012' experiment_date = datetime.strptime(datestring, '%d/%m/%Y') print experiment_date 2012-11-10 00:00:00 Once you have two datetime objects you can compare them directly: experiment_date start_date True print experiment_date - start_date 7 days, 0:00:00 Using this you can check whether the date from the data file is in between the start and end dates for each of the calibration files and then choose which calibration file to use. Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help for Python Beginner with extracting and manipulating data from thousands of ASCII files
On Sep 30, 2012 11:10 PM, Cecilia Chavana-Bryant cecilia.chav...@gmail.com wrote: Hola again Python Tutor! Hi Cecilia With a friend's help I have the following code to extract reflectance data from an ASCII data file, do a bit of data manipulation to calibrate the data and then write the calibrated file into an out file. import numpy # import glob - use if list_of_files is used dataFile = 1SH0109.001.txt #list_of_files = glob.glob('./*.txt') to replace dataFile to search for all text files in ASCII_files folder? caliFile1 = Cal_File_P17.txt # calibration file to be used on data files created from July to 18 Sep caliFile2 = Cal_File_P19.txt # calibration file to be used on data files created from 19 Sep onwards outFile = Cal_ + dataFile # this will need to change if list_of_files is used fileDate = data[6][16:26] # location of the creation date on the data files The variable data used in the line above is not created until the lines below run. I think you need to move this line down. What format does fileDate have? I guess it's a string of text from the file. If you can convert it to a datetime (or date) object it will be easy to compare with the dates as required for your calibration file. Can you show us how it looks e.g. '12-Nov-2012' or '12/11/12' or something else? #extract data from data file fdData = open(dataFile,rt) data = fdData.readlines() fdData.close() Python has a slightly better way of writing code like this: with open(dataFile, 'rt') as fdata: data = fdata.readlines() This way you don't need to remember to close the file. In fact Python will even remember to close it if there is an error. #extract data from calibration file fdCal = open(caliFile,rt) calibration = fdCal.readlines() fdCal.close() Where is caliFile set? If your going to load all the data files you might as well load both calibration files here at the beginning. #create data table k=0 #just a counter dataNum = numpy.ndarray((2151,2)) Does dataNum store integers or floating point numbers? Numpy won't let you do both in the same array. You should always specify the type of the numpy array that you want to create: dataNum = numpy.ndarray((2152, 2), float) or dataNum = numpy.ndarray((2152, 2), int) As it happens you are creating an array floats. That means that when you try to store an integer in the array below it gets converted to a float. #the actual data (the numbers) in the data file begin at line 30 for anItem in data[30:]: theNums = anItem.replace(\r\n,).split(\t) dataNum[k,0] = int(theNums[0]) dataNum[k,1] = float(theNums[1]) k+=1 #advance the counter You should look into using numpy.fromfile. This function is specifically designed for this purpose. For example: with open(dataFile) as fdata: header_lines = [fdata.readline() for _ in range(30)] dataNum = numpy.fromfile(fdata, float, sep='\t') Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help for Python Beginner with extracting and manipulating data from thousands of ASCII files
On Mon, Oct 1, 2012 at 12:33 AM, Alan Gauld alan.ga...@btinternet.comwrote: On 30/09/12 23:07, Cecilia Chavana-Bryant wrote: Hola again Python Tutor! With a friend's help I have the following code to extract reflectance data from an ASCII data file, do a bit of data manipulation to calibrate the data and then write the calibrated file into an out file. snip I have successfully calibrated one ASCII file at a time with this code. However, I have 1,000s of files that I need to calibrate so I would like some help to modify this code so it can: 1. Use one calibration file (Cal_FileP17.txt) on data files created from July to the 18th Sep and a different calibration file (Cal_FileP19.txt) for data files created from the 19th of Sep onwards. 2. Find all the .txt files in a folder called ASCII_files, which is subdivided into 12 different folders and calibrate all these files Number 2 is easier to solve and the os.walk() and glob.glob() functions should provide all the tools you need. Number 1 is more tricky since there is no obvious way to determine the arbitrary start/stop dates you specify. So I'd suggest you need to generalise the requirement to take a start/stop date as well as the calibration file name and the input data file pattern. Use those as input parameters to a function that generates the list of files to process and then calls your existing code (wrapped in a new function) and possibly provide default values for all/some of the parameters. Another option is to add the start/end dates to the calibration file if you have control of that, but personally I'd stick with input parameters... Many thanks Alan for your reply. I have added start and end dates as part of the header information for the calibration files in the date format: 01/07/2011. So, I now need to write some code to take this into consideration, any suggestions? -- 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/tutorhttp://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] Help for Python Beginner with extracting and manipulating data from thousands of ASCII files
On Mon, Oct 1, 2012 at 1:16 AM, Dave Angel d...@davea.name wrote: On 09/30/2012 06:07 PM, Cecilia Chavana-Bryant wrote: Hola again Python Tutor! With a friend's help I have the following code to extract reflectance data from an ASCII data file, do a bit of data manipulation to calibrate the data and then write the calibrated file into an out file. import numpy # import glob - use if list_of_files is used dataFile = 1SH0109.001.txt #list_of_files = glob.glob('./*.txt') to replace dataFile to search for all text files in ASCII_files folder? First, an important observation. This code has no functions defined in it. Thus it's not reusable. So every time you make a change, you'll be breaking the existing code and then trying to make the new version work. The decision of one file versus many is usually handled by writing a function that deals with one file. Test it with a single file. Then write another function that uses glob to build a list of files, and call the original one in a loop. As you work on it, you should discover that there are a half dozen other functions that you need, rather than one big one. Many thanks for this advise this helps me to get started with trying to write functions for the different procedures and then think about many files. caliFile1 = Cal_File_P17.txt # calibration file to be used on data files created from July to 18 Sep caliFile2 = Cal_File_P19.txt # calibration file to be used on data files created from 19 Sep onwards outFile = Cal_ + dataFile # this will need to change if list_of_files is used fileDate = data[6][16:26] # location of the creation date on the data files Show us the full traceback from the runtime error you get on this line. The option of using 2 different calibration files is an idea that I haven't tested yet as I am a bit lost in how to do this. I have gotten as far as adding start and end dates on both calibration files as part of the header information for each file. #extract data from data file fdData = open(dataFile,rt) data = fdData.readlines() fdData.close() #extract data from calibration file fdCal = open(caliFile,rt) Show us the full traceback from the runtime error here, as well. In the original code which uses only one calibration file this and the rest of the code works without error. calibration = fdCal.readlines() fdCal.close() #create data table k=0 #just a counter dataNum = numpy.ndarray((2151,2)) #the actual data (the numbers) in the data file begin at line 30 for anItem in data[30:]: theNums = anItem.replace(\r\n,).split(\t) dataNum[k,0] = int(theNums[0]) dataNum[k,1] = float(theNums[1]) k+=1 #advance the counter #create the calibration table k = 0 calNum = numpy.ndarray((2151,2)) for anItem in calibration[5:]: theNums = anItem.replace(\r\n,).split(\t) calNum[k,0] = int(theNums[0]) calNum[k,1] = float(theNums[1]) k+=1 #calibrate the data k=0 calibratedData = numpy.ndarray((2151,2)) for aNum in dataNum: calibratedData[k,0] = aNum[0] #first column is the wavelength calibratedData[k,1] = (aNum[1] * dataNum[k,1]) * 100.0 #second column is the measurement to be calibrated. k+=1 #write the calibrated data fd = open(outFile,wt) Error traceback ? #prior to writing the calibrated contents, write the headers for data files and calibration files fd.writelines(data[0:30]) fd.writelines(calibration[0:5]) for aNum in calibratedData: #Write the data in the file in the following format: # An integer with 3 digits, tab character, Floating point number fd.write(%03d\t%f\n % (aNum[0],aNum[1])) #close the file fd.close() Are the individual files small? By doing readlines() on them, you're assuming you can hold all of both the data file and the calibration file in memory. Both the calibration and the data files are small. The original excel calibration files have been saved as Tab delimited text files and the data files are ASCII files with 2151 rows and 2 columns. I have successfully calibrated one ASCII file at a time with this code. Unless I'm missing something, this code does not run. I didn't try it, though, just inspected it quickly. However, I have 1,000s of files that I need to calibrate so I would like some help to modify this code so it can: 1. Use one calibration file (Cal_FileP17.txt) on data files created from July to the 18th Sep and a different calibration file (Cal_FileP19.txt) for data files created from the 19th of Sep onwards. 2. Find all the .txt files in a folder called ASCII_files, which is subdivided into 12 different folders and calibrate all these files I have googled and tried thinking about how to make changes and I've managed to get myself a bit more confused. Thus, I would like some guidance on how to tackle/think about this process and how to get started.
Re: [Tutor] Help for Python Beginner with extracting and manipulating data from thousands of ASCII files
On 30/09/12 23:07, Cecilia Chavana-Bryant wrote: Hola again Python Tutor! With a friend's help I have the following code to extract reflectance data from an ASCII data file, do a bit of data manipulation to calibrate the data and then write the calibrated file into an out file. snip I have successfully calibrated one ASCII file at a time with this code. However, I have 1,000s of files that I need to calibrate so I would like some help to modify this code so it can: 1. Use one calibration file (Cal_FileP17.txt) on data files created from July to the 18th Sep and a different calibration file (Cal_FileP19.txt) for data files created from the 19th of Sep onwards. 2. Find all the .txt files in a folder called ASCII_files, which is subdivided into 12 different folders and calibrate all these files Number 2 is easier to solve and the os.walk() and glob.glob() functions should provide all the tools you need. Number 1 is more tricky since there is no obvious way to determine the arbitrary start/stop dates you specify. So I'd suggest you need to generalise the requirement to take a start/stop date as well as the calibration file name and the input data file pattern. Use those as input parameters to a function that generates the list of files to process and then calls your existing code (wrapped in a new function) and possibly provide default values for all/some of the parameters. Another option is to add the start/end dates to the calibration file if you have control of that, but personally I'd stick with input parameters... -- 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] Help for Python Beginner with extracting and manipulating data from thousands of ASCII files
On 09/30/2012 06:07 PM, Cecilia Chavana-Bryant wrote: Hola again Python Tutor! With a friend's help I have the following code to extract reflectance data from an ASCII data file, do a bit of data manipulation to calibrate the data and then write the calibrated file into an out file. import numpy # import glob - use if list_of_files is used dataFile = 1SH0109.001.txt #list_of_files = glob.glob('./*.txt') to replace dataFile to search for all text files in ASCII_files folder? First, an important observation. This code has no functions defined in it. Thus it's not reusable. So every time you make a change, you'll be breaking the existing code and then trying to make the new version work. The decision of one file versus many is usually handled by writing a function that deals with one file. Test it with a single file. Then write another function that uses glob to build a list of files, and call the original one in a loop. As you work on it, you should discover that there are a half dozen other functions that you need, rather than one big one. caliFile1 = Cal_File_P17.txt # calibration file to be used on data files created from July to 18 Sep caliFile2 = Cal_File_P19.txt # calibration file to be used on data files created from 19 Sep onwards outFile = Cal_ + dataFile # this will need to change if list_of_files is used fileDate = data[6][16:26] # location of the creation date on the data files Show us the full traceback from the runtime error you get on this line. #extract data from data file fdData = open(dataFile,rt) data = fdData.readlines() fdData.close() #extract data from calibration file fdCal = open(caliFile,rt) Show us the full traceback from the runtime error here, as well. calibration = fdCal.readlines() fdCal.close() #create data table k=0 #just a counter dataNum = numpy.ndarray((2151,2)) #the actual data (the numbers) in the data file begin at line 30 for anItem in data[30:]: theNums = anItem.replace(\r\n,).split(\t) dataNum[k,0] = int(theNums[0]) dataNum[k,1] = float(theNums[1]) k+=1 #advance the counter #create the calibration table k = 0 calNum = numpy.ndarray((2151,2)) for anItem in calibration[5:]: theNums = anItem.replace(\r\n,).split(\t) calNum[k,0] = int(theNums[0]) calNum[k,1] = float(theNums[1]) k+=1 #calibrate the data k=0 calibratedData = numpy.ndarray((2151,2)) for aNum in dataNum: calibratedData[k,0] = aNum[0] #first column is the wavelength calibratedData[k,1] = (aNum[1] * dataNum[k,1]) * 100.0 #second column is the measurement to be calibrated. k+=1 #write the calibrated data fd = open(outFile,wt) Error traceback ? #prior to writing the calibrated contents, write the headers for data files and calibration files fd.writelines(data[0:30]) fd.writelines(calibration[0:5]) for aNum in calibratedData: #Write the data in the file in the following format: # An integer with 3 digits, tab character, Floating point number fd.write(%03d\t%f\n % (aNum[0],aNum[1])) #close the file fd.close() Are the individual files small? By doing readlines() on them, you're assuming you can hold all of both the data file and the calibration file in memory. I have successfully calibrated one ASCII file at a time with this code. Unless I'm missing something, this code does not run. I didn't try it, though, just inspected it quickly. However, I have 1,000s of files that I need to calibrate so I would like some help to modify this code so it can: 1. Use one calibration file (Cal_FileP17.txt) on data files created from July to the 18th Sep and a different calibration file (Cal_FileP19.txt) for data files created from the 19th of Sep onwards. 2. Find all the .txt files in a folder called ASCII_files, which is subdivided into 12 different folders and calibrate all these files I have googled and tried thinking about how to make changes and I've managed to get myself a bit more confused. Thus, I would like some guidance on how to tackle/think about this process and how to get started. Please, I am not asking for someone to do my work and write the code for me, I would like some guidance on how to approach this and get started. Many thanks in advance for your help, Cecilia -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Python Program
First off I want to really thank you for all of the help! I am in my first semester as I started as a non traditional student in January. Even though I am in an intro class I think that many of my class mates had more of a c/s foundation in high then I did. It took me a few tries but I did finally get my program to run using this code :) #import random target = random.randint(1,100) import random #import random number generator module target = random.randint(1,100) #generates random number between 1 and 100 guess = float(raw_input('pick a number between 1 and 100')) while guess != target: if guess target: print 'too low' elif guess target: print 'too high' #otherwise guess == target and game is over I am having trouble getting it to run for more than one game but am trying. Also I started off using the idle shell to write the codes but it wont let you run it from there, so I opened a new window and retyped it for my first few attempts. I am unsure why you would use the idle shell if you would need to open a new window and retype it anyway. Is there an easier way or something that I am not getting? After doing that several times I just opened a new window and started from there without using the shell and it worked fine, so can I always do it that way and not use the shell at all? I am also still kind of unsure about the loops and was hoping you could explain a little more about it or may know of a good online resource? Thanks again for all the help...Steve really helped by explaining it simply to me and I really appreciate it! It took me like 10-15 tries but I was so excited when I finally got it to run! On 2/24/12, Steven D'Aprano st...@pearwood.info wrote: Carolina Dianne LaCourse wrote: [...] I understand that I need to ask for raw input from the user and that I need to be able to use the if elif else to tell the user whether their number matches or id too high or to low but am just not sure what to do first. Any advice would be greatly appreciated! I have tried some online tutorials to get the basics but still am having a really hard time. I did work with scratch a bit earlier this semester and got that, but am really struggling with python. Start by writing down in plain English the steps of how you would play the guessing game. This is a called an algorithm, which is something very similar to a recipe or a set of instructions. You might have something like this: (1) Think of a number between 1 and 100, and remember it. (2) Repeat the following steps until the game is over: (3) - Ask the person playing for a number between 1 and 100. (4) - If the number is too low, tell them it is too low. (5) - If the number is too high, tell them it is too high. (6) - If the number is equal to the number you thought of, the game is over. All that makes up *one* game. Then you need instructions to play multiple games: (a) Play one game, as above. (b) Repeat the following steps until done: (c) - Ask the player if they want to play again. (d) - If they say Yes, play one game, as above. (e) - Otherwise, we are done. (f) Finally, print how many games were played, how many guesses were needed, and the average number of guesses per game. Now, you need to change the English instructions to instructions the computer can follow, using Python. For example, Step (1) above picks a random number and remembers it as the target of the game: import random target = random.randint(1, 100) Step (2) is a bit harder -- it's a loop. You should have learned about while loops and for loops. I expect a while loop is better for this, because you can't tell ahead of time how many times you need to go round and round the loop. while guess != target: Step (3) ask the user for a number, and call it guess if guess target: print too low elif guess target: print too high # otherwise guess == target so the game will be over Notice that this isn't exactly Python code. The most obvious problem is the line Step (3)... which is plain English. You need to replace that with code to actually ask the user for a number. (Hint: you will need the raw_input function.) Another problem is that the *first* time you enter the loop, the name guess isn't defined. You need to give it a value to start with, before the loop. Any value will do, so long as it isn't target. I suggest 0. Does this help you get started? Go ahead and write some code, and see where it takes you. Piece by piece, step by step, you should work towards replacing each bit of English instruction with some Python code to do that. You should aim to write code to play *one* game first. Get that right, first, then adapt it to play multiple games. Write some code, see how it works (or where is fails to work), and anything that is unclear, come back and ask. -- Steven ___ Tutor maillist
Re: [Tutor] Help with Python Program
import random #import random number generator module target = random.randint(1,100) #generates random number between 1 and 100 guess = float(raw_input('pick a number between 1 and 100')) while guess != target: if guess target: print 'too low' elif guess target: print 'too high' #otherwise guess == target and game is over I am having trouble getting it to run for more than one game but am trying. Also I started off using the idle shell to write the codes but it wont let you run it from there, so I opened a new window and retyped it for my first few attempts. I am unsure why you would use the idle shell if you would need to open a new window and retype it anyway. [snip] so can I always do it that way and not use the shell at all? The shell is for testing out things; it's not really for writing entire programs in. But as a test-tool it's priceless. Don't know what random.randint() does? Use the shell to find out. Want to see if you can convert ints to floats? Use the shell. It's a great way to test short things like that, because it will give you instant feedback. You can write longer code in it, but it can be cumbersome. In the end, it's another tool for your belt, I guess you could say. I am also still kind of unsure about the loops and was hoping you could explain a little more about it or may know of a good online resource? The while loop you're using tests for one thing: is guess == target. If it isn't, the contents of the while loop executes. I should note that while your loop works, it doesn't work as intended: what happens if you guess too low? Let's see how the program runs: computer picks a number between 1 and 100 and stores it in variable 'target' computer then asks user for a number between 1 and 100 and stores it in variable 'guess' while loop checks whether guess is the same as target. If it's not, it checks if the guess is higher than target or lower than target and then prints the corresponding response. the while loop checks again if guess == target. It's not, since we never change the value of guess. It checks if the guess is higher than target or lower than target...(etc) the while loop checks again... In short, you can say that the loop is named because of its behaviour: it loops until it shouldn't any longer. I'm sure you can see the problem here. So, while you now can check whether a variable is equal to another variable, you currently have no way to change 'guess' for a new try. Can you think of any way to solve that? And while this might not be entirely on topic, there's a wonderful book for complete beginners -- I've used it as well -- that I'd like to recommend: Python Programming for the Absolute Beginner. In fact, one of the excercises happen to be this particular game. -- best regards, Robert S. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with Python Program
Hi, I have never programed before and am brand new to python also. I am trying to create a Hi-Lo game and am not really sure where to start. These are the instructions that I have. I know that I will need to import the random number generator and have looked up how to do that. I understand that I need to ask for raw input from the user and that I need to be able to use the if elif else to tell the user whether their number matches or id too high or to low but am just not sure what to do first. Any advice would be greatly appreciated! I have tried some online tutorials to get the basics but still am having a really hard time. I did work with scratch a bit earlier this semester and got that, but am really struggling with python. For your second project, you will create a Python guessing game. In this game, the user will be asked to guess a number between 1 and 100. For each guess, you will output one of three things: The user guess is correct -- tell the user he or she won, asking if he/she wants to play again. The user guess is too high -- tell him or her so. The user guess is too low -- tell him or her so. Your program should be able to run multiple games. That is, after each game, the user should be asked if they want to play again. If they type yes, then you pick a new number and play again. If they type no, then the program should say goodbye and exit. You should keep the following stats about the player's efforts: Number of games played Total number of guesses made You should output the number of games played as well as the average number of guess per game. This program will require loops (nested ones, in fact), an if-elif-else statement, and the use of Python's random number generator. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Python Program
On 2/24/2012 10:18 PM, Carolina Dianne LaCourse wrote: Hi, I have never programed before and am brand new to python also. I am trying to create a Hi-Lo game and am not really sure where to start. These are the instructions that I have. I know that I will need to import the random number generator and have looked up how to do that. I understand that I need to ask for raw input from the user and that I need to be able to use the if elif else to tell the user whether their number matches or id too high or to low but am just not sure what to do first. Any advice would be greatly appreciated! I have tried some online tutorials to get the basics but still am having a really hard time. I did work with scratch What is scratch? a bit earlier this semester and got that, but am really struggling with python. We get many requests like this. I always wonder why there is a mismatch between the course and the student. A beginner's programming class should give you the tools you need to solve the problem. Can you help us understand why this is not happening for you? I assume this is not your fault - that there is something wrong with the course and/or the instructor. As a rule we don't write the program for you; we take a look at what you've done and help you over the rough spots. Please write any amount of code you can and return with that. For your second project, What was the first project? How did that go? you will create a Python guessing game. In this game, the user will be asked to guess a number between 1 and 100. For each guess, you will output one of three things: The user guess is correct -- tell the user he or she won, asking if he/she wants to play again. The user guess is too high -- tell him or her so. The user guess is too low -- tell him or her so. Your program should be able to run multiple games. That is, after each game, the user should be asked if they want to play again. If they type yes, then you pick a new number and play again. If they type no, then the program should say goodbye and exit. You should keep the following stats about the player's efforts: Number of games played Total number of guesses made You should output the number of games played as well as the average number of guess per game. This program will require loops (nested ones, in fact), an if-elif-else statement, and the use of Python's random number generator. Do you know how to create a loop? If not, why not? Do you know how to test for low or high? If not why not? If your answers to these questions is no then (IMHO) you are in the wrong class. -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Python Program
Carolina Dianne LaCourse wrote: [...] I understand that I need to ask for raw input from the user and that I need to be able to use the if elif else to tell the user whether their number matches or id too high or to low but am just not sure what to do first. Any advice would be greatly appreciated! I have tried some online tutorials to get the basics but still am having a really hard time. I did work with scratch a bit earlier this semester and got that, but am really struggling with python. Start by writing down in plain English the steps of how you would play the guessing game. This is a called an algorithm, which is something very similar to a recipe or a set of instructions. You might have something like this: (1) Think of a number between 1 and 100, and remember it. (2) Repeat the following steps until the game is over: (3) - Ask the person playing for a number between 1 and 100. (4) - If the number is too low, tell them it is too low. (5) - If the number is too high, tell them it is too high. (6) - If the number is equal to the number you thought of, the game is over. All that makes up *one* game. Then you need instructions to play multiple games: (a) Play one game, as above. (b) Repeat the following steps until done: (c) - Ask the player if they want to play again. (d) - If they say Yes, play one game, as above. (e) - Otherwise, we are done. (f) Finally, print how many games were played, how many guesses were needed, and the average number of guesses per game. Now, you need to change the English instructions to instructions the computer can follow, using Python. For example, Step (1) above picks a random number and remembers it as the target of the game: import random target = random.randint(1, 100) Step (2) is a bit harder -- it's a loop. You should have learned about while loops and for loops. I expect a while loop is better for this, because you can't tell ahead of time how many times you need to go round and round the loop. while guess != target: Step (3) ask the user for a number, and call it guess if guess target: print too low elif guess target: print too high # otherwise guess == target so the game will be over Notice that this isn't exactly Python code. The most obvious problem is the line Step (3)... which is plain English. You need to replace that with code to actually ask the user for a number. (Hint: you will need the raw_input function.) Another problem is that the *first* time you enter the loop, the name guess isn't defined. You need to give it a value to start with, before the loop. Any value will do, so long as it isn't target. I suggest 0. Does this help you get started? Go ahead and write some code, and see where it takes you. Piece by piece, step by step, you should work towards replacing each bit of English instruction with some Python code to do that. You should aim to write code to play *one* game first. Get that right, first, then adapt it to play multiple games. Write some code, see how it works (or where is fails to work), and anything that is unclear, come back and ask. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with python-gnupg
Becky Mcquilling wrote: If anyone is familiar with python-gnupg, I am having some difficulty with the syntax. I've tried the following: When dealing with third party packages, unless it is an extremely well-known package like numpy or nltk, it is usually a good idea to link to the project's home page. Do you mean this project? http://packages.python.org/python-gnupg/ Reading the documentation, I think either of these should work: #1 encrypt data in a file input_file = open('c:/test/filename.txt', 'r') # notice that you open the file, but do not read from it. encrypted_data = gpg.encrypt_file(input_file, 'ladym...@gmail.com', output='c:/gpg_test/data.gpg2') #2 encrypt data from a string data = open('c:/test/filename.txt', 'r').read() encrypted_data = gpg.encrypt_file(data, 'ladym...@gmail.com', output='c:/gpg_test/data.gpg2') It looks like the problem you have is that you are passing the output file object, instead of just the file name. If this doesn't solve your problem, please post the exact error message in full, including the traceback, with the exact code you are using. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with python-gnupg
Thanks, everyone: Your suggestions worked. I will make sure to include full information next time. Becky On Sat, Mar 12, 2011 at 12:14 AM, Steven D'Aprano st...@pearwood.infowrote: Becky Mcquilling wrote: If anyone is familiar with python-gnupg, I am having some difficulty with the syntax. I've tried the following: When dealing with third party packages, unless it is an extremely well-known package like numpy or nltk, it is usually a good idea to link to the project's home page. Do you mean this project? http://packages.python.org/python-gnupg/ Reading the documentation, I think either of these should work: #1 encrypt data in a file input_file = open('c:/test/filename.txt', 'r') # notice that you open the file, but do not read from it. encrypted_data = gpg.encrypt_file(input_file, 'ladym...@gmail.com', output='c:/gpg_test/data.gpg2') #2 encrypt data from a string data = open('c:/test/filename.txt', 'r').read() encrypted_data = gpg.encrypt_file(data, 'ladym...@gmail.com', output='c:/gpg_test/data.gpg2') It looks like the problem you have is that you are passing the output file object, instead of just the file name. If this doesn't solve your problem, please post the exact error message in full, including the traceback, with the exact code you are using. -- Steven ___ 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] Help with python-gnupg
On Sat, Mar 12, 2011 at 1:39 AM, Becky Mcquilling ladymcse2...@gmail.com 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 pyshell#65, line 1, in module 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
On Sat, Mar 12, 2011 at 2:07 AM, David Hutto smokefl...@gmail.com 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
[Tutor] Help on Python Looping Please
Dear All, I’m new in programming and I’m studying Python now. I use Python 3.1.2 and learn from Dive Into Python 3 book (Mark Pilgrim, Thank you very much for him). I’ve learned list, tuple, set, dictionary and little bit about looping. I’m so confused about looping in first Python Program in that book (humanize.py), it’s the code: SUFFIXES = {1000: ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], 1024: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']} def approximate_size(size, a_kilobyte_is_1024_bytes=True): '''Convert a file size to human-readable form. Keyword arguments: size -- file size in bytes a_kilobyte_is_1024_bytes -- if True (default), use multiples of 1024 if False, use multiples of 1000 Returns: string ''' if size 0: raise ValueError('number must be non-negative') multiple = 1024 if a_kilobyte_is_1024_bytes else 1000 for suffix in SUFFIXES[multiple]: size /= multiple if size multiple: return '{0:.1f} {1}'.format(size, suffix) raise ValueError('number too large') if __name__ == '__main__': print(approximate_size(1, False)) print(approximate_size(1)) Result: 1.0 TB 931.3 GiB I’ve shorted the code be: SUFFIXES = {1000: ['KB','MB','GB'], 1024: ['KiB','MiB','GiB']} multiple = 1000 size = 2300 for suffix in SUFFIXES[multiple]: size /= multiple if size multiple: '{0:.1f} {1}'.format(size, suffix) '2.3 KB' '0.0 MB' '0.0 GB' *Why do in my code, it loops to all values and not in Mark Pilgrim’s code?* Best Regards, [ pyhx0r - hx0r-labs.org ] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help on Python Looping Please
On 24 February 2011 14:52, pyhx0r pyh...@gmail.com wrote: *Why do in my code, it loops to all values and not in Mark Pilgrim’s code? * Because in Mark's code the loop is terminated by the return statement (contained in the utility function approximate_size().) In your code you've removed the entire function including the return statement, consequently the loop runs to completion. Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help on Python Looping Please
On 01/-10/-28163 02:59 PM, pyhx0r wrote: Dear All, snip multiple = 1024 if a_kilobyte_is_1024_bytes else 1000 for suffix in SUFFIXES[multiple]: size /= multiple if size multiple: return '{0:.1f} {1}'.format(size, suffix) snip I’ve shorted the code be: SUFFIXES = {1000: ['KB','MB','GB'], 1024: ['KiB','MiB','GiB']} multiple = 1000 size = 2300 for suffix in SUFFIXES[multiple]: size /= multiple if size multiple: '{0:.1f} {1}'.format(size, suffix) snip *Why do in my code, it loops to all values and not in Mark Pilgrim’s code?* (Is there a reason you double-spaced all that code? It makes it very hard to read, and quite difficult to quote, since I had to delete every other line.) You wrote your code inline, and not as a function. And you omitted the return statement. So the loop won't return, it'll run to completion. Another way to exit a loop early is to use the break statement. DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help on Python Looping Please
Dear All, Thank you for your advise, it's helpful for me. NB: To DaveA, It was copy-paste from my notepad so the indentation went wrong :( +---+--+---+ | py | h | x0r | +---+--+---+ ■ 1 3 0 E2 C 9 ■ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help on Python Looping Please
On 24 February 2011 16:22, Dave Angel da...@ieee.org wrote: (Is there a reason you double-spaced all that code? It makes it very hard to read, and quite difficult to quote, since I had to delete every other line.) For what it's worth the code came out perfectly fine on my email reader (GMail). (No double spacing, courier formatted, all in all pretty easy to read. What email client are you using?) Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help on Python Looping Please
On 02/24/2011 11:55 AM, Walter Prins wrote: On 24 February 2011 16:22, Dave Angelda...@ieee.org wrote: (Is there a reason you double-spaced all that code? It makes it very hard to read, and quite difficult to quote, since I had to delete every other line.) For what it's worth the code came out perfectly fine on my email reader (GMail). (No double spacing, courier formatted, all in all pretty easy to read. What email client are you using?) Walter I use Thunderbird 3.1.7 on Linux 10.04. In text mode, naturally, but I get the same result in html mode. The prose was properly spaced, and everyone else's messagesare properly spaced. But the code in that particular message was double-spaced. DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] help with python 3.1
Dear Tutor: I would like to install a program that was written with python 3.1, the computer that I would like to put in on has Win 98SE. I tried Python 3.1.2 MSI and 2.61 but got a message that a DLL was not there and would not install. I then tried them on a Win 7 computer and got to the 5 files that you had to say where they should go. They were register ext.; TCI/TK; documentation; utility scripts; test suite---go on the HD, local drive, not at all. My guess is HD ??? Do I need all 5 files ? The writer of the program also said that you needed to download sq-3_6_23_1.zip and if you had XP or Vista and you wanted to print you also needed pywin.32-214.win32py3.1.exe. Would I need that with 98SE? He also said that any python before 3.1 would not be useable. I don't know anything about python so I need any help possible thank you Ralph duoble...@live.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help-Embedding Python in C#
On Thu, 23 Sep 2010 03:17:39 pm ranjan das wrote: What I want to do is write my code completely in Python (as gainst iron python), Iron Python *is* Python. It's just a different implementation, with built-in support for Dot-Net. copy it to the visual studio editor and create a web based application (I want it to be interactive) as against building an exe file which would mean params would have to be hard coded. How does building an exe file mean that params would have to be hard coded? What sort of params? And how does this description match what you asked earlier: I need to run/execute python module in C#. I am using python 2.6 and visual studio 10 So, which do you want to do: run Python code in a browser, or run it is C#? Objective: Write the code completely in python and then from it create a windows web based application. If it's web-based, why does it have to be Windows-only? -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help-Embedding Python in C#
Please Advise: I need to run/execute python module in C#. I am using python 2.6 and visual studio 10 Ranjan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help-Embedding Python in C#
On Wed, Sep 22, 2010 at 7:55 AM, ranjan das ranjand2...@gmail.com wrote: Please Advise: I need to run/execute python module in C#. I am using python 2.6 and visual studio 10 You should check out IronPython http://www.ironpython.com/ http://www.ironpython.com/HTH, Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help-Embedding Python in C#
Hi Wayne, Thanks for your reply. The problem is a bit more specific. I have come across ironpython and I ran a test file and it works fine as far as the wrapping is concerned. What I want to do is write my code completely in Python (as gainst iron python), copy it to the visual studio editor and create a web based application (I want it to be interactive) as against building an exe file which would mean params would have to be hard coded. While trying this I faced problems. I would prefer to do it in pure python code rather than resorting to iron python. Is that possible? Objective: Write the code completely in python and then from it create a windows web based application. Any help is appreciated Regards, Ranjan On Wed, Sep 22, 2010 at 6:38 PM, Wayne Werner waynejwer...@gmail.comwrote: On Wed, Sep 22, 2010 at 7:55 AM, ranjan das ranjand2...@gmail.com wrote: Please Advise: I need to run/execute python module in C#. I am using python 2.6 and visual studio 10 You should check out IronPython http://www.ironpython.com/ http://www.ironpython.com/HTH, Wayne -- The inherent vice of capitalism is the unequal sharing of blessings; the inherent virtue of socialism is the equal sharing of miseries. ~ Winston Churchill ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] help learning python
Hi, I'm busy with this tutorial http://www.openbookproject.net/thinkCSpy/index.html I need some feedback and help to be able to learn Python. For instance, now I'm working on chapter 8, 8.13 exercise 1, 2 and 3. Code become pretty complex for me there: http://www.openbookproject.net/thinkCSpy/ch08.html Exercise 1, I tried to solve with: mitt = Box((780, 300), mitt_x, mitt_y, filled=True, thickness=1) I added 780 and 300 as center for the paddle, is that right? Exercise 2: I have this code now: http://paste.pocoo.org/show/233057/ What do you think of the code? Is it right? Also within the context of the pong code? Next step will be to let the ball bounce back and to replace the distance function with the new hit fuction in the pong code. But I'm not sure how and where to place the call to the hit function in pong code... Please give some feedback and help. Thanks in advance, Dirk ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help on python file extension windows vista recognition
Dave Angel wrote: You will also need to get comfortable with the DOS box (Command Prompt, whatever Vista calls it. It's probably in Start-Accessories). In a DOS box, you could do a DIR of that directory, and see exactly what the file is called. You also could invoke python or pythonw explicitly on the file, with extra option switches. And when the program finishes, the window with the result wouldn't automatically vanish. And you can scroll back and see what's been happening in previous runs. And you can actually type arguments to your script. And ... If you haven't already, check out the Using Python on... section of the docs. This is an online link: http://docs.python.org/using/windows.html but the docs are included in the standard Windows install. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help on python file extension windows vista recognition
Please, I need help. I installed python on my gateway windows vista laptop computer. This is with the latest version of python (Python 2.6.3 Windows installer) Python 2.6.3 Windows installer I have some python code files I placed on my desktop and tried placing it in a folder containing python program. The files still appears on the computer as a text file. Even though I placed the .py file extension on the file. The .py is on the file but the icon image appears as a notepad file. I need help in resolving this issue. Thanks _ Hotmail: Trusted email with Microsoft’s powerful SPAM protection. http://clk.atdmt.com/GBL/go/177141664/direct/01/___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help on python file extension windows vista recognition
Victor Binns wrote: Please, I need help. I installed python on my gateway windows vista laptop computer. This is with the latest version of python (Python 2.6.3 Windows installer) Python 2.6.3 Windows installer It's not the latest, but no problem. It's probably a good choice. I have some python code files I placed on my desktop and tried placing it in a folder containing python program. Which? On the desktop, or in a folder containing python programs? The files still appears on the computer as a text file. Even though I placed the .py file extension on the file. The .py is on the file but the icon image appears as a notepad file. I need help in resolving this issue. Thanks Are you familiar with your system, and with Vista in particular? One thing that's been wrong for the last few implementations of Windows is that by default Explorer hides the extension of files. So you have to believe in icons to guess what the file extension is. When I get each new system, one of the first things I change is hide file extensions for known types. Don't hide anything. There are a number of other foolish settings which ought to be switched, but this is one of the most important. Most likely, your base problem is that your file is called myprogram.py.txt Notepad loves to add a txt extension to files, and by default Windows Explorer obscures that fact. If you must use Notepad to edit the files, then when doing the SaveAs, make sure you change the Save as file type from Text Documents to All files Otherwise Notepad will add an extra .txt to whatever extension you try to use. You will also need to get comfortable with the DOS box (Command Prompt, whatever Vista calls it. It's probably in Start-Accessories). In a DOS box, you could do a DIR of that directory, and see exactly what the file is called. You also could invoke python or pythonw explicitly on the file, with extra option switches. And when the program finishes, the window with the result wouldn't automatically vanish. And you can scroll back and see what's been happening in previous runs. And you can actually type arguments to your script. And ... DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor