[Tutor] data structure question
Hi all, I'm trying to write a small todo list/task manager and I'm having trouble creating the right data structure to hold the tasks. The program should have a command line interface. This is what I want it to do: * A list of tasks, where each task has a number of attributes. Each task should be able to have subtasks. * Persistence. * A way to display all the tasks, with subtasks indented. * A way to filter/search on the attributes of the tasks. What I've tried so far is something like this: class Task(object): def __init__(self, cargo, children=[]): self.cargo = cargo self.children = children def __str__(self): s = '\t'.join(self.cargo) return s def add_child(self,child): self.children = self.children + [child] cargo is a list of the attributes of the task, such as task text, status, deadline etc What I'm having trouble with is: * What data structure should all the Task instances be held in? * How to traverse all the tasks, both with recursion into the subtasks and not. I need the traversal both to create a nice string with the task information for printing (here I need level-aware indentation), and to be able to search the tasks by their attributes. I suspect what I need is a tree, but I want one with multiple roots. I only envision having <100 tasks at any one time so I don't need a database backend. Persistence I think I've solved by having the container data structure dump/load itself using pickle. Best regards, Alexander ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] data structure question
calendar = parsedatetime.parsedatetime.Calendar() self.__deadline = datetime.datetime(*calendar.parse(value)[0][0:7]) # datetime object is also stored in for internal use (sorting) self.int_deadline = datetime.datetime(*calendar.parse(value)[0][0:7]) def getDeadline(self): """Return deadline as a string in the format day-month.""" return self.__deadline.strftime('%d-%m %H') def setCost(self,value): """Set cost to a timedelta object.""" self.__cost = datetime.timedelta(hours=int(value)) # datetime object is also stored for internal use (sorting) self.int_cost = datetime.timedelta(hours=int(value)) def getCost(self): """Return a cost as a formatted string. Adapted from http://www.nabble.com/Formatting-timedelta-objects-td14259934.html """ hours = self.__cost.seconds // 3600 #minutes = (self.__cost.seconds % 3600) // 60 return '%sh' % (hours) # Task properties that use overloading for setting and getting. deadline = property(getDeadline,setDeadline) cost = property(getCost,setCost) # # Methods that have not been # encapsulated in TaskList. # def load(filename=False): """Load tasklist from disk using pickle.""" if not filename: filename = '.rgtddb' ts = False try: ts = pickle.load(open(filename,'rb')) ts.modified = False except IOError: print 'The file %s does not exist.' % filename return ts Best, Alexander On 1/18/08, Alan Gauld <[EMAIL PROTECTED]> wrote: > > "Tiger12506" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>def recursive_print(self, level=0): > >>print "\t"*level + self.cargo > >>for x in self.children: > >> recursive_print(x,level+1) > > > > Whoops. should be > > > > for x in self.children: > >x.recursive_print(level+1) > > Ah, you already caught it, my gmane feed ruinning a bit slow... > > Alan G > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Object Management
Hello everyone. I'm having trouble wrapping my mind around a project I'm working on. My goal is to create a program that manages (allows its users to manipulate, search by criteria and edit) objects. There is one type of object, for example I'll say it's a car. There will be a central data file containing all of the cars and multiple users will have access to it at once. I'm having trouble here, I've done some research on MOO and twisted but I'm not sure where to turn. Additionally I'll need a GUI! tkinter? Does anyone have any suggestions on how to get started with tkinter? I'm overwhelmed with the amount of documentation I've had to read and think I have to read to accomplish my goal. Thanks for reading, Alex.ander -- Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Object Management
On Tue, Jul 26, 2011 at 6:25 PM, Alan Gauld wrote: > Alexander wrote: > >> Hello everyone. I'm having trouble wrapping my mind around a project I'm >> working on. My goal is to create a program that manages (allows its users >> to >> manipulate, search by criteria and edit) objects. There is one type of >> object, for example I'll say it's a car. >> >> There will be a central data file containing all of the cars and multiple >> users will have access to it at once. I'm having trouble here, I've done >> some research on MOO and twisted but I'm not sure where to turn. >> > > I'd forget twisted etc for this, it sounds more like a traditional database > is whats needed. > > > > Additionally I'll need a GUI! tkinter? Does anyone have any suggestions on >> how to get started with tkinter? I'm overwhelmed with the amount of >> documentation I've had to read and think I have to read to accomplish my >> goal. >> > > Learning any GUI is a painful leaning curve. If you really need a desktop > client rather than a web based solution I'd look at Dabo. > It has a GUI builder (based on wxPython rather than Tkinter) and is focused > on data oriented applications. > > But if you can go down the web root then most python web frameworks will > provide both the UI and database elements for you and you get a lot of > standard functionality (login etc) for free... > > > HTH, > > Alan G. > > > -- Thanks for the replies Alan, James, and Knacktus. I'll research Django. I've been trying to work on this project for a few months and just came across the mailing list today. I appreciate your help, thanks! Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Getting Idle to work in Win7
Hi Wayne. I'm interested in the issues your facing. Could you right click on the IDLE shortcut in your start menu and tell me the details? Specifically under: *General*:* type of file, description, location, attributes*, (any *advanced * attributes?); *Shortcut*: tab, the *Target type*, *Target location *(if any), *Target*, *Start in* path, *Run *choice, any *Advanced *options? *Compatability: *anything selected here? *Security: *Are the permissions Full control? *Details: **name, type, path, owner* Looking forward to resolving the issue, Alexander. On Thu, Jul 28, 2011 at 2:38 PM, Wayne Watson wrote: > I decided to re-install. It looks like I'm in the same boat as before. > Edit with IDLE isn't even a choice. > > I tried from the command line to run pythonw.exe, and that gave me the > typical >>> input choice. Python at least works at that level. IDLE comes up > with idle.pyw. > > > On 7/27/2011 3:49 PM, Prasad, Ramit wrote: > > *From:* tutor-bounces+ramit.prasad=jpmchase@python.org [ > mailto:tutor-bounces+ramit.prasad=jpmchase@python.org] > *On Behalf Of *Walter Prins > *Sent:* Wednesday, July 27, 2011 4:39 PM > *To:* tutor@python.org > *Subject:* Re: [Tutor] Getting Idle to work in Win7 > > ** ** > > Hi > > On 27 July 2011 22:07, Wayne Watson wrote:* > *** > > It's been many months since I played with Python, and have forgotten how to > bring up IDLE. If I simply click on a py file, I see what may be a dos > window appear and quickly disappear. If I right-click on the file, and > select IDLE, the same thing happens. If I go directly to All Programs, the > same thing happens when I select IDLE. > > > There must be something wrong with your Python installation. > Right-click->"Edit with Idle" and starting IDLE from All Programs works fine > for me. (Win 7 64-bit, with both Python 2.7 and 3.2 installed.) I suggest > you reinstall Python as a start. It might also be worthwhile to try to run > your Python script from the command line, as well as starting Idle from the > command line so you can see what error message might be printed. > > Cheers > > Walter > > ** ** > > Open cmd.exe and then navigate to the directory where Python is installed > (C:\Python27) for me and then cd into the Lib\idlelib directory and run > idle.bat. Hopefully there should be some errors that show in the window. If > not you can try running it “..\..\pythonw.exe idle.pyw” and hopefully that > will show the problem. > > ** ** > > ** ** > > Ramit > > ** ** > > ** ** > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > > 712 Main Street | Houston, TX 77002 > > work phone: 713 - 216 - 5423 > > ** ** > > ** ** > > ** ** > > ** ** > > ** ** > > This communication is for informational purposes only. It is not intended > as an offer or solicitation for the purchase or sale of any financial > instrument or as an official confirmation of any transaction. All market > prices, data and other information are not warranted as to completeness or > accuracy and are subject to change without notice. Any comments or > statements made herein do not necessarily reflect those of JPMorgan Chase & > Co., its subsidiaries and affiliates. This transmission may contain > information that is privileged, confidential, legally privileged, and/or > exempt from disclosure under applicable law. If you are not the intended > recipient, you are hereby notified that any disclosure, copying, > distribution, or use of the information contained herein (including any > reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any > attachments are believed to be free of any virus or other defect that might > affect any computer system into which it is received and opened, it is the > responsibility of the recipient to ensure that it is virus free and no > responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and > affiliates, as applicable, for any loss or damage arising in any way from > its use. If you received this transmission in error, please immediately > contact the sender and destroy the material in its entirety, whether in > electronic or hard copy format. Thank you. Please refer to > http://www.jpmorgan.com/pages/disclosures for disclosures relating to > European legal entities. > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription > options:http://mail.python.org/mailman/listinfo/tutor > > > -- >Wayne Watson (Watson Adventures, Prop., Nevada City, CA) > > (121.015 Deg. W,
Re: [Tutor] Urllib Problem
On Fri, Jul 29, 2011 at 5:58 AM, Karim wrote: > ** > On 07/29/2011 11:52 AM, George Anonymous wrote: > > I am trying to make a simple programm with Python 3,that tries to open > differnet pages from a wordlist and prints which are alive.Here is the code: > from urllib import request > fob=open('c:/passwords/pass.txt','r') > x = fob.readlines() > for i in x: > urllib.request.openurl('www.google.gr/' + i) > > But it doesent work.Whats the problem? > > > Please give the exception error you get?! > And you should have in the html header > the html code error number which gives > you the fail answer from the server. > > Cheers > Karim > > As Karim noted you'll want to mention any exceptions you are getting. I'm not sure what it is you are trying to do with your code. If you'd like to try to open each line and try something if it works else an exception the code may read something similar to: fob = open('C:/passwords/pass.txt','r') fob_rlines = fob.readlines() for line in fob_rlines: try: #whatever it is you would like to do with each line except Exception: #where code didn't work and an exception occured #whatever you would like to do when a particular *Exception* occurs Hope that helps, Alexander > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription > options:http://mail.python.org/mailman/listinfo/tutor > > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Having trouble visiting the subscribers list.
On Sat, Nov 5, 2011 at 9:24 PM, Steven D'Aprano wrote: > Nathaniel Trujillo wrote: > >> I recently subscribed to tutor and I am trying to visit the subscribers >> list so I can ask a question but I wasn't given an admin address. Not only >> that but I don't know what an admin address is. Your help is greatly >> appreciated. >> > >From the website: http://mail.python.org/mailman/listinfo/tutor (*The subscribers list is only available to the list administrator.*) And for good reason. We ( you and I and other members of the list ) and not admins. Alexander > Why do you want to see the list of subscribers? That's private information. > > If you want to ask a question, ask it by sending an email to < > tutor@python.org>. > -- > Steven > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/**mailman/listinfo/tutor<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] Find all strings that....
> On 11/10/11, Original Poster Alexander Etter wrote: >> >> Hi. My friend gave me a good wake up exercise which I do not want you to >> solve for me: find all strings which can be converted to alpha with at most >> two operations, where alpha is some string constant, and a substring of at >> least length three of alpha must be in the answers. >> So, my question is: is there a library or .txt dictionary ( not the data >> type, rather the merriam webster kind ) I can use to test my script on? I'd >> imagine this library/dictionary to contain thousands of words. Not random >> words. >> Thanks for reading, >> Alexander On 10 Nov 2011, at 16:14, Alex Hall wrote: > What about just grabbing a bit text file, such as from Project > Gutenberg (sorry for the possibly incorrect spelling)? Spelling is correct. No worries. Or copying the > text from a large web-page and pasting it into a text file? I will give this a try sometime, thanks for the suggestions. However, as a member of this mailing list, it is my duty to tell you both that you have top posted in reply to the initial question. Top posting is frowned upon. Consider when John Doe finds this thread, sees the subject line, finds it appealing and decides to read it; only to find the first thing he reads is a response from somebody and not the Original post. Now Mr. Doe is scrambling through the file confused about who sent what first and where the original question is. Maybe me typing in the middle of your reply is bad, but it is distinguishable from your email and I am finding it relevant. > -- > Have a great day, > Alex (msg sent from GMail website) > mehg...@gmail.com; http://www.facebook.com/mehgcap __ On Thu, Nov 10, 2011 at 11:28 AM, Rich Lovely wrote: > If you're on linux or OSX, there's /usr/share/dict/words, which has a few > thousand words. Although no plurals, which caught me out once. If you're > on windows, it's not a hard file to find. > > > Rich "RoadieRich" Lovely > > There are 10 types of people in the world: > Those who know binary, > Those who do not, > And those who are off by one. > > Thanks Rich. I'm on Ubuntu 11.04 and Trisquel. And will make use of that file. It's an interesting collection of words, but certainly missing some of what I would want to see. Like "better" isn't in there, but "Bette" is. Anyway at least I can start coding with your suggestion. Thanks. And if you haven't seen above, please don't top post. Au revoir. Alexander E. -- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Find all strings that....
On Fri, Nov 11, 2011 at 1:38 PM, Jerry Hill wrote: > On Fri, Nov 11, 2011 at 1:21 PM, Francesco Loffredo wrote: > >> Anyway, taking for granted the rules contained in the edit distance >> definition (Thank you, Steven!), I think that finding in a given set S all >> words that can be converted into some given "target" with at most N such >> operations (better: the subset of all words in S with an edit distance >> from "target" <= N) is a very interesting and challenging task. Thank you >> (and your friend!) for this exercise, I'll give it a try. >> > > There are some standard library tools that make this pretty easy. Take a > look into difflib if you're interested. As always, there's nothing wrong > with doing it yourself so that you understand it better, of course. > > -- > Jerry > > Hi Jerry. I'm checking out difflib. Thanks for the suggestion. Alexander Etter > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Usenet comp.lang.python
Hi. Does anybody know about using the comp.lang.python usenet news feed(?) ? I'd like help configuring it. I can't seem to find documentation helping me. Thanks for reading, -- Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Usenet comp.lang.python
On Sat, Nov 19, 2011 at 6:47 PM, Alan Gauld wrote: > On 19/11/11 19:48, Alexander wrote: > >> Hi. Does anybody know about using the comp.lang.python usenet news >> feed(?) ? >> I'd like help configuring it. I can't seem to find documentation helping >> me. >> Thanks for reading, >> > > The easiest way is probably to set up your newsreader to point at the > gmane server. On Thunderbird I have the following server settings: > > Server name: news.gmane.org > Port 119 > > The rest are defaults. > > Having set up the server the rest depends on your reader, but basically > you subscribe to the news groups you are interested in. For > comp.lang.python its called: gmane.comp.python.general > > > -- > 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<http://mail.python.org/mailman/listinfo/tutor> > thanks Alan. -- Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Localhost client-server simple ssl socket test program problems
2011/12/15 Yang Chun-Kai > Hello,everyone!! > > I am writing a simple ssl client-server test program on my personal laptop. > > And I encounter some problems with my simple programs. > > Please give me some helps. > > > > My server code: > > import socket > import ssl > bindsocket = socket.socket() > bindsocket.bind(('127.0.0.1', 1234)) > bindsocket.listen(5) > print 'server is waiting for connection...' > newsocket, fromaddr = bindsocket.accept() > print 'start ssl socket...' > connstream = ssl.wrap_socket(newsocket, server_side=True, > certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt", > keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key", > ssl_version=ssl.PROTOCOL_SSLv23) > data = connstream.read() > print 'connected from address', fromaddr > print 'received data as', repr(data) > connstream.close() > > My client code: > > import socket > import ssl > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > ssl_sock = ssl.wrap_socket(s, > ca_certs="/home/ckyang/PHA/testsslsocket/myCA.crt", > cert_reqs=ssl.CERT_REQUIRED) > ssl_sock.connect(("127.0.0.1", 1234)) > ssl_sock.write("hello") > ssl_sock.close() > > > --- > Server side error: > > File "views.py", line 17, in & lt;module> > connstream = ssl.wrap_socket(newsocket, server_side=True, > certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt", > keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key", > ssl_version=ssl.PROTOCOL_SSLv23) > File "/usr/lib/python2.7/ssl.py", line 344, in wrap_socket > ciphers=ciphers) > File "/usr/lib/python2.7/ssl.py", line 119, in __init__ > ciphers) > ssl.SSLError: [Errno 336265218] _ssl.c:347: error:140B0002:SSL > routines:SSL_CTX_use_PrivateKey_file:system lib > > Client side error: > > File "client.py", line 10, in > ssl_sock.connect(("127.0.0.1", 1234)) > File "/usr/lib/python2.7/ssl.py", line 299, in connect** > self.do_handshake() > File "/usr/lib/python2.7/ssl.py", line 283, in do_handshake > self._sslobj.do_handshake() > socket.error: [Errno 104] Connection reset by peer > > > > So what is wrong with my code? > > The codes are so simple and so much like python official site sample > demonstration, but I still cant get it work, so frustrating. > > Seems the problem happened on server side then cause client side cant > connect well, is that right? > > ** > My platform is ubuntu, with openssl 0.9.8 and python 2.7. > > All certificates and keys self-signed by openssl for test convenience. > > This is the site for referrence : > http://andyjeffries.co.uk/articles/x509-encrypted-authenticated-socket-ruby-client > > Or should I need a real certificate issued by a real CA to let things work? > > Any tips or suggestions welcomed, thank you very much~ > > Good day. > > Kay > > ** > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > You're trying to connect to the same port on localhost as a client and a server? I don't know for certain but I don't think that should work. Two computers? -- Alexander 7D9C597B ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] list mail formatting
On Wed, Dec 21, 2011 at 6:51 PM, Alan Gauld wrote: > On 21/12/11 11:49, Jamie Paul Griffin wrote: >> >> Can I just ask why the majority of the mail on this list is in > >> multipart/alternative and/or html format. > > Because thats what the majority of email systems are set up to > send as default, and have been for the last 10 years or more. > >> Is there not a requirement to use plain text as with > >> most other technical mailing lists? > > No, because many of the users of this list are non technical > beginners who understand relatively little about computers. > We request, and advise where possible, on setting up email > in plain text, but we do not insist since that would deter > the very people we are trying to help. > >> I don't mean to moan and I know it's not a major issue but still. > > > It's a frustration to most folks who were brought up on > plain-text email. But most modern emailers find the idea > of using only plain text anachronistic at best and just > downright bizarre in many (most?) cases! > > -- > 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 I'm glad I came across this thread. I've been following a few posts here and there, and now that Alan has posted I feel comfortable exchanging emails for this mailing list from here on in rich formatting. -- Alexander 7D9C597B ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] list mail formatting
On Wed, Dec 21, 2011 at 11:02 PM, prakash singh wrote: > hi everybody i jsut want to login into the web page can anyone help > me please i will attach the page i just want to give username and > password using the pyhton code please help me on this.please look for > the attachment. >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor This is interesting. What networks are you connected to? And the python code you mentioned, upload it as an attachment and it will be easier to help you. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] list mail formatting
On Fri, Dec 23, 2011 at 5:24 AM, Steven D'Aprano wrote: > Alexander Etter wrote: > > Ah I know of what you mentioned. On an GNU Emacs mailing list I was >> advised to avoid anything but plaintext. It just seems so archaic. But I'm >> a novice and will learn why eventually. >> > > There's a number of reasons. In no particular order, and in all cases > "you" is generic you, not you personally. > > * Mastery of your tools. Are you the master of your tools, or are they the > master of you? If the writer can't turn off HTML mail in common mail > clients, there is little hope that he can control a compiler, an editor, > source control, etc. And if he *won't* turn it off, that shows laziness and > carelessness to others that reflects badly. Especially in the open source > coding community, including here, your reputation is worth more than gold. > > * Code is plain text. Editors sometimes use colour and formatting to > highlight parts of the code, but fundamentally, programming is about > reading and writing code. If you need fancy fonts and formatting and > dancing paperclips to get your message across, chances are you will never > be more than a mediocre programmer. > > * Mail client independence. The people you are writing to use a wide > variety of mail clients, under many different circumstances. They might be > logged into a Unix server with only a primitive command-line mail app; they > might be using mutt, or Thunderbird, or Outlook, or possibly not even > reading it via mail at all, but via a newsgroup on Usenet. All of these > programs may display your message differently. You have no control over the > presentation that the user will see -- best to make the fewest assumptions, > namely, plain text, and not rely on features which may be missing. > > * Your readers may be colour blind, and your red and green lines may look > identical. Or they may be completely blind, and using a screen reader. Or > they might prefer to disable HTML emails, and avoid all the dangers and > problems with it (security vulnerabilities, privacy breaches, and the > rest). Or they might be sick and tired of straining to reading crappy > emails with light blue text on a slightly darker blue background. Either > way, your formatting is lost. Don't expect people to turn on HTML display > just for you. > > * Layout of code (especially Python code) is special. Your mail client may > mangle the layout. It is very common to see code posted where all > indentation is lost, or even line breaks, so everything is squashed into a > single line: > >def func(a, b): while b < 100: print b b += 1 print a-b > > Or every line is separated by a blank line, which makes it a PITA to paste > into the interactive interpreter. Even if the reader can fix the mangling, > they shouldn't have to. > > > -- > Steven > > __**_ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor> > Thanks for the clarity Steven. -- Alexander 7D9C597B ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Touch Screen
Hi. Just curious if there are any ideas on how to use python with a touch screen. That is a stand alone touchscreen, not something running on a desktop or personal computer; consider a touch screen dedicated to one purpose, like a cash register, running python. Thanks, Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Touch Screen
On Mon, Jan 2, 2012 at 1:43 PM, Walter Prins wrote: > Hi, > > On 2 January 2012 18:07, Alan Gauld wrote: > > There may be a few cash registers rthat implemenmt their own embedded > > hardware monitor but the cost of developing such a thing is so high > > (especially compared to Linux!) that most devices like that use a > regular OS > > and just disguise it with a single app as the "desktop". > > Just to add to what Alan's said, and with apologies if appropriate as > its arguably only tangentially relevant to your question, but you may > be interested to keep an eye on the "Raspberry Pi", a 25$ computer > (yes, $25) that's due for release in Jan 2012. It will primarily use > Python as programming language although others will be supported. (Not > entirely suprising given that the OS is GNU/Linux.) For more see > here: > > http://en.wikipedia.org/wiki/Raspberry_Pi > > http://articles.businessinsider.com/2011-12-28/tech/30564049_1_computer-broadcom-foundation > http://www.raspberrypi.org/faqs > > It seems that for anyone who wants to build his own device on the > cheap from commodity hardware, something like this with a suitably > configured Linux distro and custom Python code makes such a project a > relative doddl. One can easily imagine building this size of device > into a cash register sized shell, perhaps with a suitably sized > touchscreen and drawer hardware interface, to build your own cash > register. (Re touchscreen's I'm thinking of something from ELO > perhaps, see: http://www.elotouch.com/Products/Touchscreens/default.asp > -- I have a friend who is working on a kiosk using a normal ITX PC > mobo and that uses an ELO screen with a GNU/Linux software stack > behind it, so that's definitely possible...) > > Cheers, > > Walter > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > Thanks for the replies gentlemen. Walter, thank you for the Raspberry Pi introduction, it may very well help me with my hobbies. I'll be certain to check it out as I develop my python and development skills. Thanks, -- Alexander 7D9C597B ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about a exercise
On Thu, Jan 5, 2012 at 10:22 AM, daedae11 wrote: > ** > The exercise is: > > Write a function which has 3 parameters. First parameter is a char, second > parameter is a integer, third parameter is a integer. > The function would create a file which have following requests: > 1. the length of the file is in accordance with the third parameter. > 2. the content of the file must be random generated. > 3. the time first parameter occurred in the content must be in accordance > with second parameter. > > please give me some hints. It would be better if you give me the code. > > -- > daedae11 > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > You're likely going to get patronized for asking for the code as if you're asking for someone to do your homework problem for you. -- Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Using Python for a client interactive map application
Dear friends, I'm emailing regarding a general question about working with Python and a web-browser based interactive map application. Over the summer I had asked a similar question and heard some things about the Django framework, does anybody have any other suggestions? For example there is a server with all the info about a map, and from a browser a user will be able to view and interact with the map at high speeds. And please remember to reply to all. Thanks, -- Alexander 7D9C597B ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Using Python for a client interactive map application
On Thu, Jan 5, 2012 at 12:16 PM, Alan Gauld wrote: > On 05/01/12 15:58, Alexander wrote: > > framework, does anybody have any other suggestions? For example there is >> a server with all the info about a map, and from a browser a user will >> be able to view and interact with the map at high speeds. >> > > High speeds? On a web application? > That usually means JavaScript and Ajax. > > That's a non trivial application. It sounds a lot like Google maps? > > Have you ever, just for fun, taken a look at the page source on a Google > maps web page? You probably won't need all of the features of Google Maps > but it might give you some idea of the scale of your challenge! > > Now, accessing a map and displaying it and even making it mouse aware, > that's a much easier task, but it may not be "high speed"... > > HTH, > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > > > __**_ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor> > Yes I'm a little familiar with ajax. My freshman year I did a presentation on ajax and google maps. Fortunately the scale of this project is far easier and less complex than Google maps, which I find contain far more data. -- Alexander 7D9C597B ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Namespace question
On Fri, Jan 20, 2012 at 2:42 PM, Emile van Sebille wrote: > On 1/20/2012 10:34 AM Tino Dai said... > > Hi everybody, >> >> Got a namespace question framed inside a Django project (but I >> still think it's pertinent to Python). We moved and broke settings.py >> four different files in a separate directory called settings. So instead >> of doing a >> >> >>> import settings >> >>> settings.whatever >> >> We are having to do: >> >> >>> import settings >> >>> settings.settings.whatever >> > > > You could > > from settings import settings > > ... which then allows access as > > settings.whatever > > > HTH, > > Emile > > > >> This is inconvenient and probably will break stuff especially with >> django framework code. Is there a way to play with the namespacing to >> have python have the former behavior rather than the latter behavior? >> >> Thanks, >> Tino >> >> >> >> __**_ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/**mailman/listinfo/tutor<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<http://mail.python.org/mailman/listinfo/tutor> > Yes I think you could also: >>> import settings as settings or >>> import settings as s ( or whatever ) -- Alexander 7D9C597B ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to read and write to a file
On Wed, Jan 25, 2012 at 7:19 AM, ken brockman wrote: > I would like to write to and read from a file from python. I wanted to use > the file to save input to the program in a list. I have been looking around > and there seems to be several ways to go about it. I tried pickling, but am > having an issue with it. What would be the correct way to accomplish this? > I have tried several ways, but to no avail. I get no error msg. but the > list isn't retaining the info. Is pickling even the best way to do it. > > file1 = open("ArtyKlikes.p", "ab") # likesList > file2 = open("ArtyDislikes.p", "ab") # dislikes > > pickle.dump(likesList, file1) > pickle.dump(dislikeList, file2) > > file1.close() > file2.close() > > Any help would be greatly appreciated. > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > Hi Ken. If you just want to read and write from a text file then you don't need to pickle. For example, (the file info.txt exists) >>>fh = open ( 'info.txt', 'w' ) >>>fh.write ( 'peter piper picked a pack of pickled peppers.' ) >>>fh.close() >>>fr = open ( 'info.txt', 'r') >>>fr.readline() 'peter piper picked a pack of pickled peppers.' >>>fr.close() or whatever. But do you have a need to use pickling? -- Alexander 7D9C597B ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to read and write to a file
On Wed, Jan 25, 2012 at 8:32 AM, ken brockman wrote: > > > > From: Alexander > To: ken brockman > Cc: "tutor@python.org" > Sent: Wednesday, January 25, 2012 7:38 AM > Subject: Re: [Tutor] how to read and write to a file > > > > On Wed, Jan 25, 2012 at 7:19 AM, ken brockman wrote: > > I would like to write to and read from a file from python. I wanted to use > the file to save input to the program in a list. I have been looking around > and there seems to be several ways to go about it. I tried pickling, but am > having an issue with it. What would be the correct way to accomplish this? I > have tried several ways, but to no avail. I get no error msg. but the list > isn't retaining the info. Is pickling even the best way to do it. > > file1 = open("ArtyKlikes.p", "ab") # likesList > file2 = open("ArtyDislikes.p", "ab") # dislikes > > pickle.dump(likesList, file1) > pickle.dump(dislikeList, file2) > > file1.close() > file2.close() > > Any help would be greatly appreciated. > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > > Hi Ken. If you just want to read and write from a text file then you don't > need to pickle. > For example, > (the file info.txt exists) > > >>>fh = open ( 'info.txt', 'w' ) > >>>fh.write ( 'peter piper picked a pack of pickled peppers.' ) > >>>fh.close() > >>>fr = open ( 'info.txt', 'r') > >>>fr.readline() > 'peter piper picked a pack of pickled peppers.' > >>>fr.close() > > or whatever. > But do you have a need to use pickling? > -- > Alexander > 7D9C597B > -- > > Hey Alexander, > I had to try it before I went to sleep. > No good. I got an error msg. TypeError: must be str, not list. > So I guess that may be why i had went with pickling. I needed something that > would work with a list. Unless there is some other way? > Thanks again for taking the time to help out. > > Ken > > Ken, pickling is used when one wants to send information through a network or communicate with a database. Somebody else here knows more about pickling than I do. As for your list problem... I'm not exactly certain what you're trying to do. But I'm going with the idea that you have two files of information, one contains strings you like, and the other contains strings you dislike. And you want to read and write this information using Python. >>> like = [ 'orange', 'blue', 'red' ] #things I like >>> dislike = [ 'apples', 'bronze', 'bananas' ] #things I dislike >>> fh = open ( 'likes.txt', 'w' ) #let's open a file stream to write # fh is my shorthand for "file handle" #writing a list to a file stream: >>> for index in range( len( like )): fh.write( like[ index ] ) fh.write ( '\n' ) #here i add a new line, maybe somebody else #knows a better way to avoid this? >>> fh.close() #now let's read that information into a list >>> fr = open ( 'info.txt' ) #I'm using python 3.2 >>> mylistoflikes = fr.readlines() >>> mylistoflikes [ 'orange\n' , 'blue\n' , 'red\n' ] >>> fr.close() -- Alexander 7D9C597B ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Deleting an object
On Sun, Jan 29, 2012 at 10:14 AM, George Nyoro wrote: > Hi all, > Last time I tried to post a question regarding this, I was asked to > clarify. Okay so here it is. There is a class called Table and objects are > just tables, you know, matrices, holding different types of data. Thing is, > I want to provide a method where one can delete the object and then if the > user tries using a variable to access a certain method or attributes, he > gets an error. Let me give an example; > > class Table: > > def delete_this(self): > > #code to delete this object or assign it null or None > > pass > > def do_something(self): > > pass > > x=Table() > > x.delete_this() > > #at this point, I want such that if I try to use x I get some sort of error > e.g. > > x.do_something() > > #Error: x is definitely not an object anymore > Hi George. Consider what it means for the object to be deleted. When one calls the table.delete_this() method what happens? Is a member variable within the Table object set to None? What members does the table object have? -- Alexander 7D9C597B ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] managing memory large dictionaries in python
On Tue, Oct 16, 2012 at 20:43 EST, Mark Lawrence wrote: > For the record Access is not a database, or so some geezer called Alex > Martelli reckons http://code.activestate.com/lists/python-list/48130/, so > please don't shoot the messenger:) > Cheers. > Mark Lawrence. Mark I don't believe your response is relevant or helpful to the original post so please don't hijack. -- 7D9C597B ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Populating a list
On Sun, Oct 21, 2012 at 9:44 PM, Saad Javed wrote: > My program downloads multiple entry values from the net. I'm trying to > combine them in a list in a particular sequence. > > l = [] > feed1 = urllib2.urlopen(rssPage1) > tree1 = etree.parse(feed1) > x = tree1.xpath("/rss/channel/item/title/text()") > y = tree1.xpath("/rss/channel/item/pubDate/text()") > z = tree1.xpath("/rss/channel/item/link/text()") > for e, f, g in zip(x, y, z): > l.append([e, f, g]) > print l > > The problem I'm facing is that the values don't combine into a single list > ("l"). It keeps printing multiple lists with three values e, f, g as the xml > tree is parsed. What is the rssPage1? Where is that part? And for readability I'd strong suggest using something other than a lowercase L. l and I look the same in some fonts. 7D9C597B ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Strings.
On Tue, Oct 23, 2012 at 7:24 PM, Nitin Ainani wrote: > Dear Sir/Madam, > > I am new to python I have a question. It is as follows: > > Suppose s is a variable and s stores empty string > > emptyString = "" #consider the string to be non-empty, that is, let's say 13 characters long (the number you chose below) string13 = "1234567890ABC" print ( string13 [ 0 ] ) >Now if we write following statement > > print ( s [ 0 ] ) # it gives error ***what error? *** The error and your example can be used to understand indexes. s [ 0 ] is asking for the value of a specific piece of s. s[0] is asking for the value at index Zero of string s. S has nothing inside of it. > > print(s[0:])# it does not give error #what does it give? > print (s[13:13]) # this too does not give error #What is the output > why? And with your other two examples I suggest understanding slicing. slice! I want the whole pie, myPie [ 0: ] #the : around an index has a special meaning. Try a string with text and observe the output of your questions. aString [ : ] aString [ : 0 ] aStr [ 1: ] etc Check it out, mess around, get back to me. Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sending email via smtplib
On Sun, Nov 18, 2012 at 12:23 AM, Saad Javed wrote: > import smtplib > > from_addr = "some_a...@hotmail.com" > to_addr = "some_a...@gmail.com" > smtp_srv = "smtp.live.com" > > subject = "Test" > message = "Test" > > msg = "To:%s\nFrom:%s\nSubject: %s\n\n%s" % (to_addr, from_addr, subject, > message) > > smtp = smtplib.SMTP(smtp_srv, 587) > smtp.set_debuglevel(1) > smtp.ehlo() > smtp.starttls() > smtp.ehlo() > smtp.login(user, passwd) > smtp.sendmail(from_addr, to_addr, msg) > smtp.quit() > > When I run this code, I get this output: > send: 'ehlo [127.0.1.1]\r\n' > reply: '250-BLU0-SMTP190.blu0.hotmail.com Hello [my-ip-address]\r\n' > reply: '250-TURN\r\n' > reply: '250-SIZE 41943040\r\n' > reply: '250-ETRN\r\n' > reply: '250-PIPELINING\r\n' > reply: '250-DSN\r\n' > reply: '250-ENHANCEDSTATUSCODES\r\n' > reply: '250-8bitmime\r\n' > reply: '250-BINARYMIME\r\n' > reply: '250-CHUNKING\r\n' > reply: '250-VRFY\r\n' > reply: '250-TLS\r\n' > reply: '250-STARTTLS\r\n' > reply: '250 OK\r\n' > reply: retcode (250); Msg: BLU0-SMTP190.blu0.hotmail.com Hello > [my-ip-address] > TURN > SIZE 41943040 > ETRN > PIPELINING > DSN > ENHANCEDSTATUSCODES > 8bitmime > BINARYMIME > CHUNKING > VRFY > TLS > STARTTLS > OK > send: 'STARTTLS\r\n' > Traceback (most recent call last): > File "sendemail.py", line 24, in > smtp.starttls() > File "/usr/lib/python2.7/smtplib.py", line 636, in starttls > (resp, reply) = self.docmd("STARTTLS") > File "/usr/lib/python2.7/smtplib.py", line 385, in docmd > return self.getreply() > File "/usr/lib/python2.7/smtplib.py", line 358, in getreply > + str(e)) > smtplib.SMTPServerDisconnected: Connection unexpectedly closed: [Errno > 104] Connection reset by peer > > I can send email via browser. Why is my authentication being blocked by > hotmail? > > P.S: I tried sending from gmail. Same error. > > Saad > > You start TLS but is the connection to the server secured using SSL? Usually email providers have particular ports and types of encryption that must be specified to authenticate before you can DL an entire inbox or send a message from the address. Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hi, First question
On Sat, Jun 15, 2013 at 1:22 AM, Patrick Williams wrote: > Hi so I am making a bit of code to extract a bit of numbers data from a > file and then find the average of that data, however while I can get the > code to extract each specific piece of data I need, I can't seem to get the > numbers to add separately so I can get a proper average. My sum1 variable > seems to only take the last bit of data entered. I was just wondering if > anyone knows what I'm doing wrong, the course I'm following hadn't started > using regex (or even proper lists) at this point, so there must be a way to > do it without. here's the code. the average of the data should be 0.6789 or > something, but I get 0.0334343 or something. > > count=0 > lst=list() > fname='mbox-short.txt' > fhand=open(fname) > for line in fhand: > if line.startswith('X-DSPAM-Confidence:'): > count=count+1 > colpos=line.find(':') > zpos=line.find('0',colpos) > num=float(line[zpos:50]) > sum1=0+num > avg=float(sum1)/int(count) > print 'Count-', count,'--', 'Average-', avg > > Any help at all is appreciated, and thanks in advance. > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > Please include the "mbox-short.txt" file. Also you should include the output of your code (copy and paste it). -- Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python error
On Wed, Jun 19, 2013 at 11:58 AM, Jack Mcgarry < iliketurtles...@googlemail.com> wrote: > Hello ,I am contacting you because I have this bug with my python that > needs solving. You see i coded this program when i was learning to do > graphical coding (still am) and i was using pygame, you may be familiar > with this program it is called skier. i clicked "run module" and ran skier > but when it ran this error came up: Traceback (most recent call last): > File "C:\Python27\skier1.py", line 1, in > import pygame, sys, random > File "C:\Python27\pygame\__init__.py", line 95, in > from pygame.base import * > ImportError: DLL load failed: %1 is not a valid Win32 application. > > my computer is 64bit and windows 7 im using python 2.7 (64bit) > > can you help? > > yes submit your code > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- Alexander Etter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] looking for volunteers with testing simple python program
On Mon, Jun 17, 2013 at 10:17 AM, Lukas Nemec wrote: > Hello, > > I changed some simple python client/server chatroom recipe > to include RSA keypair based encryption and signature verification > > because I'm sick of someone spying on my conversations on FB and similar. > > Here is the code: > > https://github.com/lunemec/python-chat > > If anyone is interrested in trying the software - mostly bughunting and > improvements > > please run these commands after downloading the source codes: > > cd client > openssl genrsa -out your_cert_name.pem -des3 4096 > openssl rsa -pubout -in yourt_cert_name.pem -passin > pass:"yourpassword" -out your_chatroom_nick.pub > > ## After this step, please send me your_chatroom_nick.pub file, it should > have the same name.pub as you want to use in the chatroom, otherwise we > can't decrypt your messages > > # if you don't have pycrypt, then sudo pip install pycrypto > python client.py your_chatroom_nick nemec.lu 3490 your_cert_name.pem > yourpassword > > Now we should be able to chat :) > > Enjoy, and please don't kill me for writing here :) > > Lukas > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > I guess this is for testing, but I have a question. If somebody sends you their .pub file (email or otherwise over internet), and a villainous third party intercepts that .pub file, will they be able to decrypt the data sent over this program? Thanks. -- Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] looking for volunteers with testing simple python program
On Tue, Jun 25, 2013 at 2:04 PM, Walter Prins wrote: > Hi Alexander > > > On 23 June 2013 22:46, Alexander wrote: > >> I guess this is for testing, but I have a question. If somebody sends you >> their .pub file (email or otherwise over internet), and a villainous third >> party intercepts that .pub file, will they be able to decrypt the data sent >> over this program? > > > While I've not looked at the actual program, it appears to use standard > public key encryption techniques. The way public key encryption works is > essentially that entities always have a public and a private key. The > public keys are always published and freely available, and are used to > *encrypt* messages for given individuals. Keys are essentially one-way, > which means you cannot de-crypt a message encrypted with the same key it > was encrypted with. Instead, only the received with the corresponding > private key can decrypt the encrypted message. > > Hence, to answer you question: If a villainous third party intercepts the > pub key, that doesn't help them in decrypting messages encrypted with that > key. At best, they can also send you encrypted messages. If they wanted to > decrypt messages meant for you they'd have to somehow gain access to your > private key. > > Regards > > Walter > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > Thanks for your response, Walter. -- Alexander Etter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Please sponsor me to run the Virgin London Marathon
Hi, Next Sunday I am going to run the London Marathon to raise money for Treehouse: an educational charity for children with autism that is very close to my heart. Autism is a condition which my cousin James and hundreds of thousands of other people in the UK suffer from. It impairs their ability to communicate and relate to the world in general. When James was very young, his parents (my uncle and aunt) and 3 other sets of parents set up Treehouse as a specialist school for children with autism, as there was really nowhere else suitable around at the time. Since then, Treehouse has grown from a school with 4 pupils, into a school with almost 100. Treehouse has also become a national autism charity, undertaking policy and parliamentary work and research to ensure autism is a national priority. The charity supports parents to campaign locally and offers training and consultancy on autism education. Treehouse provides children with an education that is vitally important to them and their families. It gives people with autism from all over the UK the chance to lead a better, more independent and more fulfilling life. Please help me to raise money for this most worthy cause by visiting my sponsorship page: http://uk.virginmoneygiving.com/alexandertelford Thank you for all your support! It really means a lot to me, Alex ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Touchscreen GUI for PyKaraoke - Job in London
Hi, I am looking for someone to write a touchscreen GUI for PyKaraoke ( http://www.kibosh.org/pykaraoke/). Looking for someone based in or around London with a lot of experience of Python and Linux who willl be able to complete this project quickly. Knowledge of sound and video processing on Linux a bonus. Please contact me for further details. Thanks, Alex ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 'word jumble' game
Hello Everyone, This is Alexander Kapshuk writing here again ... Could you please have a look at the code below and let me know of any shortcuts that could be used there. The code works fine as it is. I was just wandering if there was a better, more compact and elegant way of writing the program. Thanking you all in advance. Alexander Kapshuk # Word Jumble Game # # The computer picks a random word and then "jumbles" it. # The player has to guess the original word. # # Should the player be stuck and require a hint, they will be prompted for a hint. # If the player answers 'yes', the appropriate hint will be displayed and the player will be asked to guess again. # If the player answers 'no', they will be asked to guess again and awarded some points if they manage to guess the jumbled word without ever asking for a hint. import random # create a sequence of words to choose from WORDS = ("python", "jumble", "easy", "difficult", "answer", "xylophone") # pick one word randomly from the sequence word = random.choice(WORDS) # create a variable to use later to see if the guess is correct correct = word # create hints for all the jumbled words hint0 = "\nIt's the best programming language for the absolute beginner ...\n" hint1 = "\nIt's what this program does to words to make it difficult to guess them ...\n" hint2 = "\nIt's not difficult ...\n" hint3 = "\nIt's not easy ...\n" hint4 = "\nIt's not a question ...\n" hint5 = "\nIt's a musical instrument you have to hit with 2 small sticks ...\n" # create a jumbled version of the word jumble = "" while word: position = random.randrange(len(word)) jumble += word[position] word = word[:position] + word[(position + 1):] # start the game print \ """ Welcome to Word Jumple! Unscramble the letters to make a word. (Press the enter key at the prompt to quit.) """ print "The jumble:", jumble guess = raw_input("\nYour guess: ") guess = guess.lower() score = 0 while (guess != correct) and (guess != ""): print "\nSorry, that's not it.\n" hint_prompt = raw_input("Would you like a hint? Y/N: ") hint_prompt = hint_prompt.lower() if hint_prompt == "yes" and correct == WORDS[0]: print hint0 elif hint_prompt == "yes" and correct == WORDS[1]: print hint1 elif hint_prompt == "yes" and correct == WORDS[2]: print hint2 elif hint_prompt == "yes" and correct == WORDS[3]: print hint3 elif hint_prompt == "yes" and correct == WORDS[4]: print hint4 elif hint_prompt == "yes" and correct == WORDS[5]: print hint5 elif hint_prompt == "no": score += 50 guess = raw_input("Your guess: ") guess = guess.lower() if guess == correct and hint_prompt == "no": print "\nThat's it! You guessed it!\n" print "Because you never asked for a hint you get", score, "points.\n" print "\nThanks for playing." raw_input("\n\nPress the enter key to exit.") ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Problem with "Hello, World"
So I've written my first python program (the ubiquitous 'Hello, World'). Already, I'm having problems. First, the question I can't find the answer to. Where (exactly) am I supposed to save my files? When I wrote "hello.py" there was no clearly stated "Make sure you save it HERE or else Python won't know where to look for it." In case that won't solve the problem, here are the gory details. I wrote "hello.py" with TextWrangler. I can get it to run from TextWrangler by clicking on the "run in terminal" command. And it runs beautifully. A masterful demonstration of my ability to follow directions. But I can't get it to run directly from Python. If I go to the terminal and type "python hello.py" (which is what the instructions say I should be doing!) I get the following: hello.py Traceback (most recent call last): File "", line 1, in ? NameError: name 'hello' is not defined When I run debugger (in TextWrangler) I get the following: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/pdb.py", line 9, in ? import cmd File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/cmd.py", line 48, in ? import string File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/string.py", line 83, in ? import re as _re File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/re.py", line 5, in ? from sre import * File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/sre.py", line 97, in ? import sre_compile File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/sre_compile.py", line 17, in ? assert _sre.MAGIC == MAGIC, "SRE module mismatch" AssertionError: SRE module mismatch logout [Process completed] All help gratefully taken with both hands! Alex ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] can python run under windows 95?
Hello Everyone, Quick question ... I've got an old Toshiba Satellite 110CT laptop with Windows 95 installed on it. It's got 40 MB of RAM and a 3 GB hard drive. Would I be able to run Python on it? If so, what version of Python should I install? I've tried installing Python 2.5 on it, but got a message saying that the installation file could not be unpacked. What could the problem be? Thanking you all in advance and looking forward to hearing from you, Alexander Kapshuk. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] problems with running IDLE under Windows 95
Hello to All of the Python Community, I'd like to thank all those who replied to my last email about Python not installing under Windows 95. That problem's been overcome. Although, after installing Python 2.5.1 I ran into another difficulty. IDLE wouldn't start. Another thing I did was uninstall Python 2.5.1 and install Python 2.2.3 to see if it would make any difference. It didn't. I'd click on the IDLE icon, the hourglass thing would come up for a few seconds and then it would disappear. What could the problem be there? Thanking you in advance and looking forward to hearing from those of you who may have an answer. Regards, Alexander Kapshuk ISD Education Office ICQ#295-121-606 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IDLE running fine now under Windows 95:-)
IDLE in Python 2.2.3 working fine on my laptop now. I'd like to give Python 2.5.1 one more try though:-). Looks like it didn't 'seem' to run not because there was something wrong with the laptop or Windows as such, but because of the USER not being patient enough. It's an old beaten up thing that requires a certain amount of patience on the part of the user. I was able to run it successfully for the first time by accessing it directly from Python22\Tools\Idle\idle.py and then the 2nd time by clicking on the IDLE icon on my desktop. So, sorry for causing much ado about nothing:-). Thank you all once again. Regards, Alexander Kapshuk ISD Education Office ICQ#295-121-606 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] software modeling tools used with Python
Dear Python Community, I was just wondering about what software modelling tools are normally used to design Python programs. I have heard of Star UML. Has anyone used it to design their programs? What else is available out there? Thanking you all in advance. Alexander Kapshuk ISD Education Office ICQ#295-121-606 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] software modeling tools used with Python
Thanks for your reply, Alan. I'm not there yet, as in I'm not a very experienced Python programmer and I'm still in the early stages of learning the language and programming as a whole. What I'm looking for is a way to design my programs, big or small, other than just pseudo-coding them on a piece of paper. How do you design your programs? Regards, Alexander Kapshuk ISD Education Office ICQ#295-121-606 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] software modeling tools used with Python
Thanks a lot Danny. Will definitely look into those things. Regards, Alexander Kapshuk ISD Education Office ICQ#295-121-606 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] software modeling tools used with Python
Thanks, Alan. The whole situation is clear as day now. Alexander Kapshuk ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python query
Dear All, My name is Alexander Kapshuk. I'm interested in learning to program in Python. I have very little programming experience. I've learnt some basics of programming with Logo. I've downloaded Python 2.5 for Windows XP Professional. I would appreciate any advice on what to do next. What books/tutorials to use? I understand that learning a programming language involves practice. So, I suppose, I could use a book/tutorial with loads of practical code samples to try out. Any other practical advice you may deem feasible would be welcome. Thanking you in advance. Alexander Kapshuk. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] breaking the 'while' loop
Dear All, I have been learning computer programming with Python only for a short while. I have a question to do with breaking the while loop. I have attached the source code of a program called 'Guess my number' with the while loop running until the right number is guessed. I want to limit the number of tries to 5. To do that, I have tried the if structure along with the break statement immediately below the 'tries += 1' line: if tries > 5: break print "Wrong guess!" Which still did not result in the while loop breaking after attempt No 5. I would appreciate being explained what I am doing wrong. Regards, Alexander Kapshuk guess_my_number.py Description: guess_my_number.py ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] guess my number game
I'm working on a program that has the user think of a number between 1 and 100 and then tries to guess that number. I'm having trouble telling the computer to keep on looking for the correct number, each time narrowing down the search range. Please see the code below. import random print "\tWelcome to 'Guess My Number 1.2'!" print "\nThink of a number between 1 and 100." print "The computer will try to guess it in as few attempts as possible.\n" # set the initial values user_number = int(raw_input("Think of a number between 1 and 100 and press Enter: ")) guess = random.randrange(50) + 1 answer = "" tries = 1 # guessing loop print guess answer = raw_input("Is the above No '>', '<' or '=' as your No?: ") while (answer != "="): if (answer == ">"): print (guess = random.randrange(100) + 51) elif (answer == "<"): print (guess = random.randrange(49) + 1) elif (answer == "="): print "Correct! The number was", user_number "And it only took you", tries " tries!\n" else: print "Keep on trying!" tries += 1 raw_input("\n\nPress the enter key to exit.") Thanking you all in advance. Alexander Kapshuk ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Tkinter Expanding Canvas with AutoScrollBar
Hi Tutors, Thanks in advance for all the advice you've already given to others... it has been extremely useful! I'm working on a project, and I wanted to have a header, a footer and an expanding canvas with (possibly) many widgets inside it. I simply modified Fred Lundh's auto-hiding scrollbar code found here - http://effbot.org/zone/tkinter-autoscrollbar.htm It is almost working as hoped - but I have the problem that the canvas only resizes smaller, not larger - even when the canvas is too large to display in the original window! I'll attach my code... I'm just not sure what's going wrong: # from Tkinter import * class AutoScrollbar(Scrollbar): # a scrollbar that hides itself if it's not needed. only # works if you use the grid geometry manager. def set(self, lo, hi): if float(lo) <= 0.0 and float(hi) >= 1.0: # grid_remove is currently missing from Tkinter! self.tk.call("grid", "remove", self) else: self.grid() Scrollbar.set(self, lo, hi) def pack(self, **kw): raise TclError, "cannot use pack with this widget" def place(self, **kw): raise TclError, "cannot use place with this widget" # # create scrolled canvas al = Tk() al.columnconfigure(0,weight=1) al.rowconfigure(0,weight=1) header = Frame(al) header.pack(side= TOP, expand = YES) htxt = Label(header,text='TOP TOP TOP... this is the TOP') htxt.pack() footer = Frame(al) footer.pack(side = BOTTOM, expand = YES) ftxt = Label(footer,text='BOTTOM BOTTOM BOTTOM... this is the BOTTOM!') ftxt.pack() root = LabelFrame(al, bd=2, text='Data',relief='groove',padx=5, pady=5) root.pack(side = TOP, expand = YES) vscrollbar = AutoScrollbar(root) vscrollbar.grid(row=0, column=1, sticky=N+S) hscrollbar = AutoScrollbar(root, orient=HORIZONTAL) hscrollbar.grid(row=1, column=0, sticky=E+W) canvas = Canvas(root, yscrollcommand=vscrollbar.set, xscrollcommand=hscrollbar.set) canvas.grid(row=0, column=0, sticky=N+S+E+W) vscrollbar.config(command=canvas.yview) hscrollbar.config(command=canvas.xview) # make the canvas expandable root.grid_rowconfigure(0, weight=1) root.grid_columnconfigure(0, weight=1) # create canvas contents frame = Frame(canvas) frame.rowconfigure(1, weight=1) frame.columnconfigure(1, weight=1) rows = 20 for i in range(1,rows): for j in range(1,20): button = Button(frame, padx=7, pady=7, text="[%d,%d]" % (i,j)) button.grid(row=i, column=j, sticky='news') canvas.create_window(0, 0, anchor=NW, window=frame) frame.update_idletasks() canvas.config(scrollregion=canvas.bbox("all")) root.mainloop() # Thanks, Al ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tkinter Expanding Canvas with AutoScrollBar
Well. I solved my own problem. Mainly I wasn't using the grid manager everywhere, and I think that's what was messing it up! Thanks anyways! Al On Mon, Feb 9, 2009 at 12:29 PM, Alexander Grant wrote: > Hi Tutors, > Thanks in advance for all the advice you've already given to others... it > has been extremely useful! > > I'm working on a project, and I wanted to have a header, a footer and an > expanding canvas with (possibly) many widgets inside it. > > I simply modified Fred Lundh's auto-hiding scrollbar code found here - > http://effbot.org/zone/tkinter-autoscrollbar.htm > It is almost working as hoped - but I have the problem that the canvas only > resizes smaller, not larger - even when the canvas is too large to display > in the original window! > > I'll attach my code... I'm just not sure what's going wrong: > > > # > from Tkinter import * > > class AutoScrollbar(Scrollbar): > # a scrollbar that hides itself if it's not needed. only > # works if you use the grid geometry manager. > def set(self, lo, hi): > if float(lo) <= 0.0 and float(hi) >= 1.0: > # grid_remove is currently missing from Tkinter! > self.tk.call("grid", "remove", self) > else: > self.grid() > Scrollbar.set(self, lo, hi) > def pack(self, **kw): > raise TclError, "cannot use pack with this widget" > def place(self, **kw): > raise TclError, "cannot use place with this widget" > > # > # create scrolled canvas > > al = Tk() > al.columnconfigure(0,weight=1) > al.rowconfigure(0,weight=1) > > header = Frame(al) > header.pack(side= TOP, expand = YES) > > htxt = Label(header,text='TOP TOP TOP... this is the TOP') > htxt.pack() > > footer = Frame(al) > footer.pack(side = BOTTOM, expand = YES) > > ftxt = Label(footer,text='BOTTOM BOTTOM BOTTOM... this is the BOTTOM!') > ftxt.pack() > > root = LabelFrame(al, bd=2, text='Data',relief='groove',padx=5, pady=5) > root.pack(side = TOP, expand = YES) > > vscrollbar = AutoScrollbar(root) > vscrollbar.grid(row=0, column=1, sticky=N+S) > hscrollbar = AutoScrollbar(root, orient=HORIZONTAL) > hscrollbar.grid(row=1, column=0, sticky=E+W) > > canvas = Canvas(root, > yscrollcommand=vscrollbar.set, > xscrollcommand=hscrollbar.set) > canvas.grid(row=0, column=0, sticky=N+S+E+W) > > vscrollbar.config(command=canvas.yview) > hscrollbar.config(command=canvas.xview) > > # make the canvas expandable > root.grid_rowconfigure(0, weight=1) > root.grid_columnconfigure(0, weight=1) > > # create canvas contents > > frame = Frame(canvas) > frame.rowconfigure(1, weight=1) > frame.columnconfigure(1, weight=1) > > rows = 20 > for i in range(1,rows): > for j in range(1,20): > button = Button(frame, padx=7, pady=7, text="[%d,%d]" % (i,j)) > button.grid(row=i, column=j, sticky='news') > > canvas.create_window(0, 0, anchor=NW, window=frame) > > frame.update_idletasks() > > canvas.config(scrollregion=canvas.bbox("all")) > > root.mainloop() > # > > > > Thanks, > > Al > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] vim as a python editor
Some high profile ruby hackers have put together a pretty snazzy set of vim/gvim configs together on github at https://github.com/carlhuda/janus On the topic of configuring Capslock to be an escape key, it's because that's where the "meta" key used to be on old school unix keyboards, and so it makes you double plus unix if you reconfigure things that way(also has the plus of rendering emacs a lot more usable). On Fri, Jan 7, 2011 at 7:22 PM, Steven D'Aprano wrote: > Alan Gauld wrote: > >> "Paul Griffiths" wrote >> >>> I've learned that: >>> ... >>> - re-configuring the Caps Lock to be an extra Esc saves time >>> >> >> Huh? How do you use that? Its a new one on me. Why would two escape keys >> be useful? >> > > What if you want to escape the escape, so that (say) esc-C is the same as > just C? > > > Not-very-helpfully y'rs, > > -- > 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
[Tutor] Basic question on spaces
Hello; I'm a new student of Python using "Python Programming for Absolute Beginners" 3rd edition by Michael Dawson as my guide. This is a basic question regarding spaces. I'm not sure how to make it so spaces do not show up between variables and basic strings, particularly before commas and after dollar signs, as in the simple "tipper" program I have below. #Tip program: calculates 15% and 20% tip for a given bill. bill = int(input("Hello! Welcome to the tipper program. \nWhat is the amount of " "your bill, in dollars please: ")) percent15 = bill * .15 percent20 = bill * .20 print("\nOkay, based on that bill, a 15% tip would be $", percent15, ", and \n" "a 20% tip would be $", percent20, ".") input("\n\nPress the enter key to exit.") As you can see, this is quite rudimentary; I have not discovered any special function that eliminates spaces yet, if such a function exits. The problem is, as stated above, unwanted spaces after both dollar signs, before the comma after '15.0' and before the period after '20.0." Apologies for asking such a basic question, but any help will be appreciated. -Alex ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Basic program question
Hello- I am running Python v 3.1.1. As an exercise, I wrote a simple coin flipper program, where the computer flips a coin 100 times and then prints out the number of heads and tails. My program crashes immediately if I run it normally through the command line, but if I go to "Run- Run Module," it seems to work just fine. I can't seem to figure out why. I've pasted the relevant code below- any help will be greatly appreciated. Thanks! import random print("\tWelcome to the 'Coin Flipper' program!") counter = 0 heads = 0 tails = 0 while counter < 100: the_number = random.randint(1, 2) if the_number == 1: heads += 1 else: tails += 1 counter += 1 print("\nI flipped the coint 100 times.") print("It came up heads", heads, "times and tails", tails, "times.") print("\n\nPress the enter key to exit.") _ -Alex ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Assigning range
Does anyone know how to assign a certain numerical range to a variable, and then choose the number that is the middle of that range? For example, I want to assign the variable "X" a range between 1 and 50, and then I want to have the middle of that range (25) return with some command when I call it (perhaps rangemid or something like that?). In pseudocode, I am trying to say X = range [1,50], return middle of range (which should return 25) but I don't know how to code it. This is for a basic program I'm trying to write where the player thinks of a number and the computer tries to guess the number in as few tries as possible. Thanks for any help! -Alex ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Assigning range
Thanks Steven- I'll try that out. -Alex On Wed, Jul 27, 2011 at 5:40 PM, Steven D'Aprano wrote: > Alexander Quest wrote: > >> Does anyone know how to assign a certain numerical range to a variable, >> and >> then choose the number that is the middle of that range? For example, I >> want >> to assign the variable "X" a range between 1 and 50, and then I want to >> have >> the middle of that range (25) return with some command when I call it >> (perhaps rangemid or something like that?). In pseudocode, I am trying to >> say X = range [1,50], return middle of range (which should return 25) but >> I >> don't know how to code it. This is for a basic program I'm trying to write >> where the player thinks of a number and the computer tries to guess the >> number in as few tries as possible. Thanks for any help! >> > > > Forget about using range, that just adds meaningless complexity. > > What is important is that you have a lower bound, and a higher bound: two > numbers, instead of how ever many (possible thousands, or millions!) in > range(low, high). > > middle = (low+high)//2 > > > > -- > Steven > > __**_ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/**mailman/listinfo/tutor<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] Assigning range
Thanks for that Donald! -Alex On Wed, Jul 27, 2011 at 8:16 PM, Donald Wilson wrote: > You could start with an anonymous function using the lambda operator, such > as: > > > > mid_range = lambda x: x[len(x) // 2] > > Note: If you use len(x) / 2 in python 3.x you will get a TypeError because > the division operator / returns a float. Floor // returns an int in 2.x and > 3.x. > > Then use either: > > x = range(1000, 4001) > mid_x = mid_range(x) # mid_x == 2500 > > or… > > mid_x = mid_range(range(500, 751)) # mid_x == 625 > > etc. to retrieve the middle element. > > You can extract the mid point of any sequence type, such as a string, using > this function. > > mid_x = mid_range(‘12345678987654321’) # mid_x == ‘9’ > > > > middle_number = lambda lo, hi: abs(lo - hi) // 2 > > will work if you just need the mid point of two numbers; either ints or > floats. > > mid_x = middle_number(0, 1000) # mid_x = 500 > > DW > > On Jul 27, 2011, at 8:16 PM, Alexander Quest wrote: > > > Does anyone know how to assign a certain numerical range to a variable, > and then choose the number that is the middle of that range? For example, I > want to assign the variable "X" a range between 1 and 50, and then I want to > have the middle of that range (25) return with some command when I call it > (perhaps rangemid or something like that?). In pseudocode, I am trying to > say X = range [1,50], return middle of range (which should return 25) but I > don't know how to code it. This is for a basic program I'm trying to write > where the player thinks of a number and the computer tries to guess the > number in as few tries as possible. Thanks for any help! > > > > -Alex > > ___ > > Tutor maillist - Tutor@python.org > > To unsubscribe or change subscription options: > > http://mail.python.org/mailman/listinfo/tutor > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Running files from command prompt
I downloaded the google's python exercise files from their website ( http://code.google.com/edu/languages/google-python-class/set-up.html), unzipped them, and placed them in C. I then added the following to the PATH variable under system settings so that I could type "python" in command prompt and have Windows start the interpreter: C:\Python31;C:\Python31\Tools\Scripts When I type in "python" in the command prompt, the interpreter opens, but when I try to open one of the programs from the Google exercise files (hello.py), I get the following error: Traceback : File "", line 1, in NameError: name 'hello' is not defined Or, if I just type in "python hello.py" first in the command prompt (as opposed to typing in python, hitting enter, and THEN typing in hello.py, as above), I get the following error: python: can't open file 'hello.py': [Errno 2] No such file or directory. So I guess my question is how do I run .py files from the command prompt now that I seem to have gotten Windows to recognize and open the interpreter when I type in "python"? Thanks for any help. -Alex P.S. Just as an aside, when I open up the command prompt, the initial directory is C:\Users\Alexander, but my google exercises are in C:\google-python-exercises and python itself is in C:\Python31. I don't know if this makes a difference or not. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running files from command prompt
Awesome- thanks for that Dave! The programs all work now, except that the google exercise programs are all from Python 2.X and I'm running 3.1, so some of them are giving me errors. Is there a way around this or do I have to download a 2.X version so I can run these without a problem? Thanks again. -Alex On Thu, Jul 28, 2011 at 7:11 PM, Dave Angel wrote: > On 07/28/2011 09:58 PM, Alexander Quest wrote: > >> I downloaded the google's python exercise files from their website ( >> http://code.google.com/edu/**languages/google-python-class/**set-up.html<http://code.google.com/edu/languages/google-python-class/set-up.html> >> ), >> unzipped them, and placed them in C. >> I then added the following to the PATH variable under system settings so >> that I could type "python" in command prompt and have Windows start the >> interpreter: C:\Python31;C:\Python31\Tools\**Scripts >> >> When I type in "python" in the command prompt, the interpreter opens, but >> when I try to open one of the programs from the Google exercise files >> (hello.py), I get the following error: >> Traceback: >>File "", line 1, in >> NameError: name 'hello' is not defined >> >> > When you're running the python interpreter, you can't just type the name of > your script. You need to import it > import hello > > However, first it needs to be in the python's module search path. Easiest > way is to make > it your current directory. > > So, from a command prompt: > > cd C:\google-python-exercises > > python > starting Python version > > >>>>import hello > > > > Or, if I just type in "python hello.py" first in the command prompt (as >> opposed to typing in python, hitting enter, and THEN typing in hello.py, >> as >> above), I get the following error: >> >> >> python: can't open file 'hello.py': [Errno 2] No such file or directory. >> >> So I guess my question is how do I run .py files from the command prompt >> now >> that I seem to have gotten Windows to recognize and open the interpreter >> when I type in "python"? Thanks for any help. >> >> Similarly, before running python, change to the directory you want the > script to run in. > Normally, you'd do: > > cd c:\google-python-exercises > python hello.py > > > > -Alex >> >> P.S. Just as an aside, when I open up the command prompt, the initial >> directory is C:\Users\Alexander, but my google exercises are in >> C:\google-python-exercises and python itself is in C:\Python31. I don't >> know >> if this makes a difference or not. >> >> > > -- > > DaveA > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running files from command prompt
To clarify, the particular file that was giving me trouble was the basic "hello world" file. The original code on line 29 read as such: print 'Hello', name When I ran "C:\google-python-exercises> python hello.py, it gave me an error on that line (line 29), but when I changed that line to print ('Hello', name), that is, including the parentheses, it printed out "hello world" as it should. I'm assuming that this means that one of the differences between Python 2.X and Python 3.X is that the print function necessitates parentheses in the latter versions but not in the former. I am a bit confused as to why this is, assuming I am correct in my assumption above, because I was under the impression that code written for earlier python versions will work for later python versions, as is the case here. Anyways, I just wanted to add this info to clarify my last question regarding whether or not I should install Python 2.X and uninstall Python 3.1 that I have now, since I'm guessing that doing the google exercises will continue to give me these errors with other programs (but this is, of course, still assuming that the error cited above truly is caused by version incompatibility). -Alex On Thu, Jul 28, 2011 at 7:58 PM, Alexander Quest wrote: > Awesome- thanks for that Dave! The programs all work now, except that the > google exercise programs are all from Python 2.X and I'm running 3.1, so > some of them are giving me errors. Is there a way around this or do I have > to download a 2.X version so I can run these without a problem? Thanks > again. > > -Alex > > > On Thu, Jul 28, 2011 at 7:11 PM, Dave Angel wrote: > >> On 07/28/2011 09:58 PM, Alexander Quest wrote: >> >>> I downloaded the google's python exercise files from their website ( >>> http://code.google.com/edu/**languages/google-python-class/**set-up.html<http://code.google.com/edu/languages/google-python-class/set-up.html> >>> ), >>> unzipped them, and placed them in C. >>> I then added the following to the PATH variable under system settings so >>> that I could type "python" in command prompt and have Windows start the >>> interpreter: C:\Python31;C:\Python31\Tools\**Scripts >>> >>> When I type in "python" in the command prompt, the interpreter opens, but >>> when I try to open one of the programs from the Google exercise files >>> (hello.py), I get the following error: >>> Traceback: >>>File "", line 1, in >>> NameError: name 'hello' is not defined >>> >>> >> When you're running the python interpreter, you can't just type the name >> of your script. You need to import it >> import hello >> >> However, first it needs to be in the python's module search path. Easiest >> way is to make >> it your current directory. >> >> So, from a command prompt: >> >> cd C:\google-python-exercises >> >> python >> starting Python version >> >> >>>>import hello >> >> >> >> Or, if I just type in "python hello.py" first in the command prompt (as >>> opposed to typing in python, hitting enter, and THEN typing in hello.py, >>> as >>> above), I get the following error: >>> >>> >>> python: can't open file 'hello.py': [Errno 2] No such file or directory. >>> >>> So I guess my question is how do I run .py files from the command prompt >>> now >>> that I seem to have gotten Windows to recognize and open the interpreter >>> when I type in "python"? Thanks for any help. >>> >>> Similarly, before running python, change to the directory you want the >> script to run in. >> Normally, you'd do: >> >> cd c:\google-python-exercises >> python hello.py >> >> >> >> -Alex >>> >>> P.S. Just as an aside, when I open up the command prompt, the initial >>> directory is C:\Users\Alexander, but my google exercises are in >>> C:\google-python-exercises and python itself is in C:\Python31. I don't >>> know >>> if this makes a difference or not. >>> >>> >> >> -- >> >> DaveA >> >> > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running files from command prompt
Alexander- thanks for the tip as to sticking with Python 3. Steven, I greatly appreciate that breakdown. You're right about the error: it was a syntax error on that line; I'll make sure to include the descriptions in the future. As far as finding a new tutorial, I am going to see if Google's class works out with Python 3.1, and if not, I'll switch over to a different one. -Alexander On Thu, Jul 28, 2011 at 10:27 PM, Steven D'Aprano wrote: > Alexander Quest wrote: > >> To clarify, the particular file that was giving me trouble was the basic >> "hello world" file. The original code on line 29 read as such: print >> 'Hello', name >> When I ran "C:\google-python-exercises> python hello.py, it gave me an >> error >> on that line (line 29), but when I changed that line to print ('Hello', >> name), that is, including the parentheses, it printed out "hello world" as >> it should. I'm assuming that this means that one of the differences >> between >> Python 2.X and Python 3.X is that the print function necessitates >> parentheses in the latter versions but not in the former. >> > > > Yes, that is correct. > > To be a programmer (whether professional or amateur), you need to learn to > *pay attention to the error given*. "It gave me an error" is meaningless. > What does the error message say? > > In this case, I expect it is a SyntaxError. But you need to learn to read > the error message and understand what it is trying to tell you. Some errors > are cryptic and don't help, but generally speaking Python is pretty good > about giving useful error messages: > > > >>> a = [1, 2, 3] > >>> len a > File "", line 1 >len a >^ > SyntaxError: invalid syntax > > > Admittedly you do need to learn that Python functions require parentheses, > but apart from that, the error tells you what is wrong: you can't follow a > function len with another name a without something between them. This is > illegal syntax. > > > > > I am a bit >> confused as to why this is, assuming I am correct in my assumption above, >> because I was under the impression that code written for earlier python >> versions will work for later python versions, as is the case here. >> > > Not quite. It is (mostly) true for Python 1.x and 2.x, but Python 3 has > deliberately included some backwards incompatible changes. The biggest two > are that strings are now Unicode rather than byte strings, and that print is > now a function instead of a statement. So, yes, in Python 3 you have to call > it with parentheses. > > The differences are still quite minor -- think of Python 2.x and Python 3.x > being like the differences between American English and British English. > Provided you pay attention to the error messages, and remember to add round > brackets after print, tutorials for 2.x should still *mostly* work. > > > > I just wanted to add this info to clarify my last question regarding >> whether >> or not I should install Python 2.X and uninstall Python 3.1 that I have >> now, >> > > Personally, I would consider it wiser to find a Python 3 tutorial. Python 3 > is the future, and you will need to learn it eventually. > > > > > -- > Steven > __**_ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/**mailman/listinfo/tutor<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] How to replace the '\'s in a path with '/'s?
On Jul 31, 2011, at 1:28, "Richard D. Moores" wrote: > 64-bit Vista > Python 3.2.1 > > I would like to write a function that would take a path such as > 'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf' > and return 'C:/Users/Dick/Desktop/Documents/Notes/College Notes.rtf' . I've > tried this: > > def test(path): >return path.replace('\', '/') > > print(test('C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf')) > > gets me > > File "c:\P32Working\untitled-5.py", line 2 >return path.replace('\', '/') >^ > SyntaxError: EOL while scanning string literal > Process terminated with an exit code of 1 > > Thanks, > > Dick > Hi Dick. EOL means End-of-line. Try using double slashes when specifying a path. The back slash \ by itself may be interpreted as an escape character or keyword. For example: print(test('C:\\Users\\Dick\\Desktop\\Documents\\Notes\\CollegeNotes.rtf')) Hope that helps, Alexander > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Mailing list documentation
Hello everyone, is there a page that contains documentation for this mailing list? I've seen a few users top post and others advise against it; if there isn't a page listing conventions let's create it and if there is what is it's URL and how do you suggest users read it? Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Indexing a list with nested tuples
Hi guys- I'm having a problem with a list that has nested tuples: attributes = [("strength", 0), ("health ", 0), ("wisdom ", 0), ("dexterity", 0)] I've defined the list above with 4 items, each starting with a value of 0. The player enters how many points he or she wants to add to a given item. The selection menu is 1 - strength; 2 - health; 3 - wisdom; 4- dexterity. So the "selection" variable is actually 1 more than the index location of the intended item. So I have the following code: print("Added ", points, "to ", attributes[selection-1][0], "attribute.") My intent with this is to say that I've added this many points (however many) to the corresponding item in the list. So if the player selects "1", then selection = 1, but I subtract 1 from that (selection -1) to get the index value of that item in the list (in this case 0). Then I have [0] to indicate that I want to go to the second value within that first item, which is the point value. I get an error saying that list indices must be integers, not strings. I get a similar error even if I just put attributes[selection][0] without the minus 1. Also, it seems that the tuple within the list cannot be modified directly, so I can't add points to the original value of "0" that all 4 items start with. Is there a way to keep this nested list with tuples but be able to modify the point count for each item, or will it be better to create a dictionary or 2 separate lists (1 for the names "Strength, Health, Wisdom, Dexterity" and one for their starting values "0,0,0,0")? Any suggestions/help will be greatly appreciated!!! -Alex ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Indexing a list with nested tuples
Thanks Peter- I tried the replacement method where the entire tuple is replaced with a new one and that worked. Changing the "attribute_index" (or "selection" variable, as I called it) to an integer removed the int/str errors. -Alex On Wed, Aug 3, 2011 at 12:12 AM, Peter Otten <__pete...@web.de> wrote: > Alexander Quest wrote: > > > Hi guys- I'm having a problem with a list that has nested tuples: > > > > attributes = [("strength", 0), ("health ", 0), ("wisdom ", 0), > > ("dexterity", 0)] > > > > I've defined the list above with 4 items, each starting with a value of > 0. > > The player > > enters how many points he or she wants to add to a given item. The > > selection menu > > is 1 - strength; 2 - health; 3 - wisdom; 4- dexterity. So the "selection" > > variable is actually > > 1 more than the index location of the intended item. So I have the > > following code: > > > > print("Added ", points, "to ", attributes[selection-1][0], "attribute.") > > > > My intent with this is to say that I've added this many points (however > > many) to the > > corresponding item in the list. So if the player selects "1", then > > selection = 1, but I subtract > > 1 from that (selection -1) to get the index value of that item in the > list > > (in this case 0). Then I > > have [0] to indicate that I want to go to the second value within that > > first item, which is the > > point value. I get an error saying that list indices must be integers, > not > > strings. I get a similar > > error even if I just put attributes[selection][0] without the minus 1. > > > > Also, it seems that the tuple within the list cannot be modified > directly, > > so I can't add points to the original value of "0" that all 4 items start > > with. Is there a way to keep this nested list with > > tuples but be able to modify the point count for each item, or will it be > > better to create a dictionary or 2 separate lists (1 for the names > > "Strength, Health, Wisdom, Dexterity" and one > > for their starting values "0,0,0,0")? Any suggestions/help will be > greatly > > appreciated!!! > > [I'm assuming you are using Python 3. If not replace input() with > raw_input()] > > Let's investigate what happens when you enter an attribute index: > > >>> attribute_index = input("Choose attribute ") > Choose attribute 2 > >>> attribute_index > '2' > > Do you note the '...' around the number? > > >>> attribute_index -= 1 > Traceback (most recent call last): > File "", line 1, in > TypeError: unsupported operand type(s) for -=: 'str' and 'int' > > It's actually a string, not an integer; therefore you have to convert it to > an integer before you can do any math with it: > > >>> attribute_index = int(attribute_index) > >>> attribute_index > 2 > >>> attribute_index -= 1 > >>> attribute_index > 1 > > Now let's try to change the second tuple: > > >>> attributes = [ > ... ("strength", 0), ("health", 0), ("wisdom", 0), ("dexterity", 0)] > >>> attributes[attribute_index] > ('health', 0) > >>> attributes[attribute_index][1] += 42 > Traceback (most recent call last): > File "", line 1, in > TypeError: 'tuple' object does not support item assignment > > The error message is pretty clear, you cannot replace items of a tuple. > You can either to switch to nested lists > > [["strength", 0], ["health", 0], ...] > > or replace the entire tuple with a new one: > > >>> name, value = attributes[attribute_index] > >>> attributes[attribute_index] = name, value + 42 > >>> attributes > [('strength', 0), ('health', 42), ('wisdom', 0), ('dexterity', 0)] > > However, I think the pythonic way is to use a dictionary. If you want the > user to input numbers you need a second dictionary to translate the numbers > into attribute names: > > >>> attributes = dict(attributes) > >>> lookup = {1: "strength", 2: "health", 3: "wisdom", 4: "dexterity"} > >>> while True: > ... index = input("index ") > ... if not index: break > ... amount = int(input("amount ")) > ... name = lookup[int(index)] > ... attributes[name] += amount > ... > index 1 > amount 10 > index 2 > amount 20 > index 3 > amount 10 > index 2 > amount -100 > index > >>> attributes > {'dexterity': 0, 'strength': 10, 'health': -38, 'wisdom': 10} > > Personally I would ask for attribute names directly. > > ___ > 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] Indexing a list with nested tuples
Hi Bob- thanks for the reply again. I apologize about not "replying all" last time- still getting in the habit of doing this. I am using Python version 3.1. As far as tuples are concerned, I don't NEED to use them, but I am trying to get some practice with them. This is because I am following an instructional book that is discussing nested tuples within lists. The way I get the "selection" variable from the user is just by typing the following: selection = input("Selection: ") I'm not sure why it reads it initially as a string, but I later included the line selection = int(selection), which solved the int/str problem. Also, I was about to switch to dictionaries or just lists without tuples, but another poster above stated that I could just replace the entire tuple item within the list, which technically would not be changing the tuple, so it worked out. The only problem I have now is trying to sort the 4 attributes based on their numerical value, not their alphabetical value. But when I type in attributes.sort(reverse=True), it sorts them alphabetically because the name of the attribute is 1st in the list, and its value is 2nd. Here it is again for reference: attributes = [("strength", 0), ("health ", 0), ("wisdom ", 0), ("dexterity", 0)] Sorry if this is a bit confusing. Thanks for your help and tips so far Bob. -Alex On Wed, Aug 3, 2011 at 5:52 AM, bob gailer wrote: > On 8/2/2011 11:39 PM, Alexander Quest wrote: > > Hey Bob- thanks for the reply. Here is a more complete part of that code > section (the ellipses are parts where I've deleted code because I don't > think it's important for this question): > > > Please always reply-all so a copy goes to the list. > > Thanks for posting more code & traceback > > I forgot to mention earlier - tell us which version of Python you are using > (this looks like version 3) > > You did not answer all my questions! How come? Please do so now. > > > > _ > attributes = [("strength", 0), ("health ", 0), ("wisdom ", 0), > ("dexterity", 0)] > . > . > . > print( > """ > 1 - Strength > 2 - Health > 3 - Wisdom > 4 - Dexterity > > Any other key - Quit > """ > ) > selection = input("Selection: ") > if selection == "1" or selection == "2" or selection == "3" or selection == > "4": > print("You have ", points, "points available.") > how_many = input("How many would you like to add to this > attribute?: ") > while how_many < 0 or how_many > 30 or how_many == > "": # Because max points available is 30, and > entering less than 0 does not make sense. > print("Invalid entry. You have ", points, "points > available.") # If the user enters a number > less than 0, greater than 30, or just presses enter, it loops. > how_many = input("How many would you like to add to > this attribute?: ") > print("Added ", points, "to ", attributes[selection-1][0], > "attribute.") # Here is where I try to add the > number of points to the value, based on what the user entered. > points = points - > how_many > # I subtract the number of points added from the total points available. > attributes[selection-1][1] += > how_many # I > add the number of points the user selected to the variable selected. > > > __ > > > Here's the traceback I get: > > Traceback (most recent call last): > File "C:\Users\Alexander\Desktop\Python Practice\Ch05-2.py", line 54, in > > print("Added ", points, "to ", attributes[selection-1][0], > "attribute.") > TypeError: unsupported operand type(s) for -: 'str' and 'int' > _ > > Thanks for any help. I understand that I can't change tuples directly, but > is there a way to change them indirectly (like saying attribute.remove[x] > and then saying attribute.append[x] with the new variable? But this seems to &
Re: [Tutor] Indexing a list with nested tuples
My bad- meant to say [1]. Thanks. -Alexander On Fri, Aug 5, 2011 at 12:36 PM, Christopher King wrote: > > > On Tue, Aug 2, 2011 at 10:44 PM, Alexander Quest wrote: >> >> have [0] to indicate that I want to go to the second value within that >> first item, which is the >> point value >> > Actually [0] is the first element. I would go with [1]. > > > ___ > 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] GNU Emacs and Python
On Oct 31, 2011, at 15:31, Tim Johnson wrote: > * Rinu Boney [111031 07:03]: >> I Use Windows.I Already Know C/C++ which makes python syntax seem very easy. >> Maybe Setting Up Emacs With Python Will Make Me Productive. >> I Have Eclipse With PyDev. >> Why Is There Not A Pythonic Emacs? > Rinu, by this time I believe that Alan has addressed your question > above. He has also (wisely) provided caveats regarding the > difficulty of learning emacs itself. > > I'll take a reverse of Alan's comments, not to contradict him, but > to give a possible different perspective: > > If you learn to use emacs with python, you will essentially be > learning *two* programming languages: Python _and_ elisp, which is > the internal programming language of emacs. Emacs is essentially > an elisp interpreter. There may be advantages to learning two > languages simultaneously. > > This will take time. A lot of time. Do you have the time? Will you > be compensated for the time? :) having two additional programming > languages "under your belt" may be considered compensation. > > In case you do not know this: Emacs has the ability to run the > python or language-your-choice interpreter asynchronous within the > editor, in it's own window. There could be great advantages to > this. I have in the past, written elisp code that allows me two > write code in one window and have it evaluated in the 'python > window' or 'language-of-your-choice window'. > > I'll reiterate what I said earlier, I no longer use emacs, but > have great respect for it. I use vim linked against the python > binary so that I can use python code to enhance my (hand-rolled) > "IDE". I much prefer python code to elisp code. > > I hope my comments are of some help. I'm sure that you have been > well informed as to what you would be getting youself into. :) > regards > -- > Tim Rinu, I use emacs. I use Python and C++. I'm also a university student. Last semester I learned python 2.7 using IDLE, and continued with IDLE while I searched for alternatives over the summer. I didn't find what I was looking for. Say, just a few weeks ago I started my C++ course and switched to emacs since the professor was using it. I tried it, read the easy to understand documentation, and I am so productive, jubilant, and satisfied with GNU Emacs. It's extensible beyond immediate comprehension; like a sunflower it starts as a seed, sprouts leaves, etc; I'm elaborating the infinite usability of emacs. There is a learning curve. One may find a learning curve with everything in existence, whereas I repudiate one discouraging another for the aforementioned. Those who desire the power of emacs seek it. Tim, do you use GNU Emacs? >From what literature I've encountered including a wikipedia page I believe >there is a satiric starwars-like cold-war feud between users of vi and emacs. I'm neutral and won't judge an entity or patronize one for their use of free will. I'm happy. Forgive me if I appear too anything. Good Day. Alexander Etter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
On Nov 1, 2011, at 12:47, Chris Hare wrote: > > I am working on a python Tk program which involves a login window and I am > looking for some advice. > > Currently the code I have creates a window (Toplevel) where the login > controls are and I am running that using a main loop for the window. The > root window is hidden. The objective is that when the user ha successfully > authenticated, the login window is closed or the main loop os exited and then > the root window is shown and the main loop started for the actual application. > > Questions: > 1. Is this the best way of doing this or is there a better way? > 2. How do I exit the main loop when the user has authenticated? > > Thanks > > Chris Hare > ch...@labr.net > > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor Hi, hopefully a more experience hacker can provide clarity, but how secure does this login need to be? I dont much about python in DRAM but your login sounds like it could be easily hacked. Alexander___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] GNU Emacs and Python
On Nov 1, 2011, at 16:06, Wayne Werner wrote: > On Tue, Nov 1, 2011 at 6:31 AM, Alexander Etter wrote: > There is a learning curve. > > Yes, and for a graphical comparison of learning curves: > http://jeetworks.org/files/images/emacs_learning_curves.png > > ;) > > One may find a learning curve with everything in existence, whereas I > repudiate one discouraging another for the aforementioned. > Those who desire the power of emacs seek it. > Tim, do you use GNU Emacs? > >From what literature I've encountered including a wikipedia page I believe > >there is a satiric starwars-like cold-war feud between users of vi and emacs. > I'm neutral and won't judge an entity or patronize one for their use of free > will. > > I think these days a lot more people have become more pragmatic (or maybe I > just hang around more levelheaded people now ;) but there are few better ways > to start a flame war on IRC or USENET than ask the question which is better - > vi or emacs. > > I "grew up" using vim, and I personally prefer modal editing - something > about my brain prefers the clear distinction between writing my code and > editing my code. For a while I tried emacs (mainly because I started learning > Lisp, and I was working at a .NET shop and they had some horribly basic emacs > shortcuts), and got lots of wrist cramps using chords for everything, even > after I changed the caps key to control like it should be. > > My only recommendation is that you should learn emacs, vim, (or both, if > you're crazy like I was ;) because you will be a *much* more productive > programmer, simply because you can do things with both emacs and vim that you > cannot do in more basic editors. > > Anyhow, just my two-bits. > -Wayne I like than .png image! It does appear vi biased though! Alexander___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Find all strings that....
Hi. My friend gave me a good wake up exercise which I do not want you to solve for me: find all strings which can be converted to alpha with at most two operations, where alpha is some string constant, and a substring of at least length three of alpha must be in the answers. So, my question is: is there a library or .txt dictionary ( not the data type, rather the merriam webster kind ) I can use to test my script on? I'd imagine this library/dictionary to contain thousands of words. Not random words. Thanks for reading, Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Find all strings that....
On Nov 10, 2011, at 13:52, Francesco Loffredo wrote: > Alexander Etter wrote: >> >> Hi. My friend gave me a good wake up exercise which I do not want you to >> solve for me: find all strings which can be converted to alpha with at most >> two operations, where alpha is some string constant, and a substring of at >> least length three of alpha must be in the answers. > I'd like to try this exercise too; would you mind defining "operations" more > specifically, please? > Given a sufficiently broad meaning of "operations" (e.g. operation = any > function call) > then any word can be converted into any given word with at most ONE operation. Consider an operation not as a function. A function could easily contain more than two operations. An operation would remove two letters. An operation would add one letter. Etc. Alexander > >> So, my question is: is there a library or .txt dictionary ( not the data >> type, rather the merriam webster kind ) I can use to test my script on? I'd >> imagine this library/dictionary to contain thousands of words. Not random >> words. > http://www.cs.nmsu.edu/~hfugal/cs167/labs/words.txt >> Thanks for reading, >> Alexander > More thanks for writing! > Francesco > > > - > Nessun virus nel messaggio. > Controllato da AVG - www.avg.com > Versione: 2012.0.1869 / Database dei virus: 2092/4606 - Data di rilascio: > 09/11/2011 > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Suggest Book
On Nov 11, 2011, at 9:29, Pankaj Jakhar wrote: > Hello > > Please suggest me the best book for Python from which I can learn basics to > advanced Python. > > Thank you. > > PankaJ Jakhar > I'm sure Alan or one of our veteran list members will have something to say, but at my school for a class called "intro to problem solving" or something like that CS1114, the book used is by T. Gaddis, "Introduction to Python". I think. I may be incorrect. I'll check it out on amazon. Alexander > ___ > Tutor - 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] Shorten Code.
On Nov 18, 2011, at 13:15, ALAN GAULD wrote: > > > > for var in [value,value_1]: > > >var = "green" > > > > Um, that won't work. You typed that example too quickly. > > Oops! Yes. You'd need to enumerate and access the variables > via an index. yuk. Don't do it folks! :-) > > Excuse: It was early morning and I hadn't had any coffee... > > Alan G. > In your defense Alan, after you typed that code in your response you mentioned the necessity of defining the variables: >But you need to have already created the variables >somewhere and unless there >is a big list its not usually >worth while. Alexander Etter > ___ > 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] Blacklist?
I'm top posting because the link below is spam. Does the email address who sent the message get blacklisted or punished? Alexander On Nov 27, 2011, at 4:45, Mario Cavett wrote: > Hola. > finally my aunt gave me a push in the right direction this turned my luck > around now im making my way to the top I promise youll love it > http://gabfair.com/profile/29DavidScott/ > see you later > ___ > 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] Blacklist?
On Nov 27, 2011, at 17:55, Steven D'Aprano wrote: > Alexander Etter wrote: >> I'm top posting because the link below is spam. > > > Why on earth do you think that it is acceptable to repeat spam on the list > just because you top post? > > If you have to reply to spam, does your backspace key not work? ESPECIALLY > the spammer's URL. > > -- > Steven > Sorry Steven! I've learned my lesson. Alexander. > ___ > 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] list mail formatting
On Dec 22, 2011, at 4:10, Alan Gauld wrote: > On 22/12/11 03:34, Alexander wrote: > >>> We request, and advise where possible, on setting up email >>> in plain text, but we do not insist > >>> It's a frustration to most folks who were brought up on >>> plain-text email. >> >> I'm glad I came across this thread. I've been following a few posts >> here and there, and now that Alan has posted I feel comfortable >> exchanging emails for this mailing list from here on in rich >> formatting. > > Notice I didn't say we encourage it. If you can send mails in plain tesxt you > will avoid many problems, particularly in code formatting issues. You will > also avoid frustrating those who might help you. > > But, if you can't figure out how to send in plain text we would rather you > posted RTF than not post at all! > > But if you ever want to grow as a programmer and use any of the more advanced > technical mailing lists you will find them less accomodating. > So avoiding plain text may work here but will ultimately be limiting to your > learning. > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > > __ Ah I know of what you mentioned. On an GNU Emacs mailing list I was advised to avoid anything but plaintext. It just seems so archaic. But I'm a novice and will learn why eventually. Alexander. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Zip, tar, and file handling
On Jan 6, 2012, at 22:57, daedae11 wrote: > I was asked to write a program to move files between ZIP(.zip) and > TAR/GZIP(.tgz/.tar.gz) or TAR/BZIP2(.tbz/.tar.bz2) archive. > > my code is: > > > import zipfile; > import tarfile; > import os; > from os import path ; > > def showAllFiles(fileObj): > if fileObj.filename.endswith("zip"): > if isinstance(fileObj, zipfile.ZipFile): > print "j"*20; > for name in fileObj.namelist(): > print name; > else: > for name in fileObj.getnames(): > print name; > > def moveFile(srcObj, dstObj): > fileName = raw_input("input the name of the file to move: "); > srcObj.extract(fileName); > if isinstance(dstObj, zipfile.ZipFile): > dstObj.write(fileName); > else: > dstObj.addfile(tarfile.TarInfo(fileName)); > os.remove(fileName); > > def main(): > intro = """ > enter a choice > (M)ove file from source file to destinatiom file > (S)how all the files in source file > (Q)uit > your choice is: """ > srcFile = raw_input("input the source file name: "); > dstFile = raw_input("input the destination file name: "); > while True: > with ( zipfile.ZipFile(srcFile, "r") if srcFile.endswith("zip") else > tarfile.open(srcFile, "r"+":"+path.splitext(srcFile)[1][1:]) ) as srcObj, \ > ( zipfile.ZipFile(dstFile, "r") if >dstFile.endswith("zip") else > tarfile.open(dstFile, "w"+":"+path.splitext(dstFile)[1][1:]) ) as > dstObj: > choice = raw_input(intro)[0].lower(); > if choice == "s": > showAllFiles(srcObj); > elif choice == "m": > moveFile(srcObj, dstObj); > elif choice == "q": > break; > else: > print "invalid command!" > > if __name__ == '__main__': > main(); > > But there are some problems. > 1. It could extract file successfully, but can't add files to .tar.gz file. > 2. I think it's a little tedious, but I don't know how to improve it. > > Please give me some help , thank you! > > daedae11 > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor Hi there. I would start by handling file extensions other than ZIP in your first two functions. Why not handle if the file is a tgz or tbz within the functions. Also I don't see the purpose of the first function, "showallfiles" it prints out twenty "j"s? Looking forward to your response. Alexander___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] exercise with classes
On Feb 2, 2012, at 12:36, Tonu Mikk wrote: > I feel stumped and don't know how to go about creating this game with two > classes. > > So far I have searched for info on how to pass variables from one class to > another and have been able to create a small two class program (attached). > Thank you, > Tonu > > __ Hi Tonu. I'm fairly certain that your second class is missing the most important function of a class, the __init__ function! It's necessary to initialize the object. Add it to your second class and see how it changes things. Alexander___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Notepad++ question
Hey all; my question is regarding editing Python code in Notepad++. When I run this piece of code in Notepad++: def fix_start(s): var1 = s[0] var2 = "*" var3 = s.replace(var1, var2) return var3 I get an indentation error, which reads: File "C:\google-python-exercises\google-python-exercises\basic>string1.py line 56 var2 = "*" ^ IndentationError: unexpected indent The thing is that in Notepad++, that code does not appear with an indentation where var2 is. It appears like this: def fix_start(s): var1 = s[0] var2 = "*" var3 = s.replace(var1, var2) return var3 but when I copy and paste it, it pastes with an indentation where var2 is, which is what I think is causing the error. The code runs fine if I just use IDLE. I am doing Google's python exercises, and they recommended I edit the settings on Notepad++ to indent 2 spaces upon a tab, this being the convention at Google. Does anyone know what the deal is here? Also, I am wondering why use Notepad++ or other such programs when IDLE seems to be fine for writing code. Thanks. -Alex ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Notepad++ question
Got it Dave- sorry about not sending it to the newsgroup as well. My question was regarding a piece of boilerplate code: if __name__ == '__main__': main() This calls the main function, but I don't understand what the 'if' statement is doing here. In the simple programs that I've seen this so far, there is no variable called "_name_", and even if there was, why is it comparing it to "_main_"? Why can't the main function just be called by typing main()- why do we need this if statement to precede it? Thanks. -Alex On Thu, Jun 7, 2012 at 6:16 PM, Dave Angel wrote: > On 06/07/2012 02:36 PM, Alexander Quest wrote: > > Ok, thanks guys. I also had one more quick question regarding a piece of > > boilerplate code: > > > > To get a response, you will needs to leave your question at the python > tutor newsgroup. We are part of a group, not offering private advice. > > Normally, you just do a Reply-all to one of the existing messages on the > thread, to include the group. But you can also typetutor@python.org > as a CC: > > I've been volunteering my time on various forums for over 25 years now, > so I think I speak for lots of other volunteers. > > > -- > > DaveA > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Notepad++ question
[Resending because I messed up on last email] My question was regarding a piece of boilerplate code: if __name__ == '__main__': main() This calls the main function, but I don't understand what the 'if' statement is doing here. In the simple programs that I've seen this so far, there is no variable called "_name_", and even if there was, why is it comparing it to "_main_"? Why can't the main function just be called by typing main()- why do we need this if statement to precede it? Thanks. -Alex On Thu, Jun 14, 2012 at 3:17 PM, Alexander Quest wrote: > Got it Dave- sorry about not sending it to the newsgroup as well. > > My question was regarding a piece of boilerplate code: > > > if __name__ == '__main__': > main() > > This calls the main function, but I don't understand what the 'if' > statement is doing here. In the simple programs that I've seen this so far, > there is no variable called "_name_", and even if there was, why is it > comparing it to "_main_"? Why can't the main function just be called by > typing main()- why do we need this if statement to precede it? Thanks. > > -Alex > > On Thu, Jun 7, 2012 at 6:16 PM, Dave Angel wrote: > >> On 06/07/2012 02:36 PM, Alexander Quest wrote: >> > Ok, thanks guys. I also had one more quick question regarding a piece of >> > boilerplate code: >> > >> >> To get a response, you will needs to leave your question at the python >> tutor newsgroup. We are part of a group, not offering private advice. >> >> Normally, you just do a Reply-all to one of the existing messages on the >> thread, to include the group. But you can also typetutor@python.org >> as a CC: >> >> I've been volunteering my time on various forums for over 25 years now, >> so I think I speak for lots of other volunteers. >> >> >> -- >> >> DaveA >> > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Notepad++ question
Thanks Walter; I believe I understand the reasoning behind it, though not all of the mechanics, but for now, your answer is more than sufficient. -Alex On Thu, Jun 14, 2012 at 4:10 PM, Walter Prins wrote: > Hi Alex, > > On 14 June 2012 23:18, Alexander Quest wrote: > > if __name__ == '__main__': > > main() > > > > This calls the main function, but I don't understand what the 'if' > statement > > is doing here. In the simple programs that I've seen this so far, there > is > > no variable called "_name_", and even if there was, why is it comparing > it > > to "_main_"? Why can't the main function just be called by typing main()- > > why do we need this if statement to precede it? Thanks. > > In short, consider the implications of the fact that your file, apart > from being a program that can run standalone, might also be a Python > module that might be used in another program. Oftentimes you want to > write your Python code in such a way that when the module is run > directly you want it to do something useful (such as run a main() > function, e.g. maybe run some unit/self-tests or whatever), while when > you import it for use in another program/module then you probably > rather do *not* want it to run as if it is itself the "main program". > So, in order to differentiate the 2 cases, there exists the above > Python idiom. So, when a module is directly run as the "main > program", then the name of the module being run, which is reflected by > the variable __name__, made available by the Python interpreter, will > be equal to "__main__", while when it's imported it will be equal to > the module name. This allows your module to know when it's running > whether it's running as the main program or just running because it's > been imported by another module. > > Does that answer your question? > > Walter > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Re.findall question
I'm a bit confused about extracting data using re.search or re.findall. Say I have the following code: tuples = re.findall(r'blahblah(\d+)yattayattayatta(\w+)moreblahblahblah(\w+)over', text) So I'm looking for that string in 'text', and I intend to extract the parts which have parentheses around them. And it works: the variable "tuples", which I assigned to get the return of re.findall, returns a tuple list, each 'element' therein being a tuple of 3 elements (which is what I wanted since I had 3 sets of parentheses). My question is how does Python know to return just the part in the parentheses and not to return the "blahblah" and the "yattayattayatta", etc...? The 're.search' function returns the whole thing, and if I want just the parentheses parts, I do tuples.group(1) or tuples.group(2) or tuples.group(3), depending on which set of parentheses I want. Does the re.findall command by default ignore anything outside of the parentheses and only return the parentheses as a grouping withing one tuple (i.e., the first element in "tuples" would be, as it is, a list comprised of 3 elements corresponding respectively to the 1st, 2nd, and 3rd parentheses)? Thank you for reading. -Alex ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Returning multiple objects from a function
Hello- I'm wondering how to access specific objects returned from a function when that function returns multiple objects. For example, if I have "return(list1, list2, list 3)" within a function "mainFunc()" that takes no arguments, how do I use list1, list2, and list3 outside of the function once they are returned by that function? Thank you. -Alex ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Returning multiple objects from a function
I understand the basics of tuples, but that formulation returned the following error: Traceback (most recent call last): File "C:\Users\Owner\Desktop\MIT\Sets\Set3.py", line 34, in list4 = tuplesresult[1] TypeError: 'NoneType' object is not subscriptable When I tried to assign "tuplesresult[1]" to the variable "list4" (after assigning tuplesresult = mainFunc(), which is the name of the function that returns the tuple in my program), the error occurred. That aside, is it all right if I just code "return list1, list2" without the parens? In that case, how would I access list1 and list2 when needed? Thanks for your help. On Mon, Jul 2, 2012 at 4:11 PM, Walter Prins wrote: > On 2 July 2012 23:55, Alexander Q. wrote: > > Hello- I'm wondering how to access specific objects returned from a > function > > when that function returns multiple objects. > > > > For example, if I have "return(list1, list2, list 3)" within a function > > When you have: > return (list1, list2, list3) > > ... you're actually returning a single tuple object. Read about > tuples in the documentation. To access an item from a tuple you index > into it, e.g. > > tupleresult = myfunc() > x = tupleresult[0] > > ... for example > > Walter. > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Returning multiple objects from a function
On Mon, Jul 2, 2012 at 8:56 PM, Dave Angel wrote: > On 07/02/2012 10:23 PM, Alexander Q. wrote: > > I understand the basics of tuples, but that formulation returned the > > following error: > > > > Traceback (most recent call last): > > File "C:\Users\Owner\Desktop\MIT\Sets\Set3.py", line 34, in > > list4 = tuplesresult[1] > > TypeError: 'NoneType' object is not subscriptable > > > > When I tried to assign "tuplesresult[1]" to the variable "list4" (after > > assigning tuplesresult = mainFunc(), which is the name of the function > that > > returns the tuple in my program), the error occurred. That aside, is it > all > > right if I just code "return list1, list2" without the parens? In that > > case, how would I access list1 and list2 when needed? > > That's no different: list1, list2 is a tuple of size 2. > > Thanks for your help. > > > You top-posted, which loses all the context of the earlier messages. > Please put your new message AFTER the part you're quoting > > Anyway, you never showed the function mainFunc(), but from the error > traceback message, it didn't return anything, which means None. > > Chances are you have something like: > > def mainFunc(): > if something: > return 4, 12 > > > And if the if fails, the function will return None. To fix that, make > sure all paths through the function return a similar object, generally a > tuple of the same size. > > > > -- > > DaveA > > Ok thanks- I will try that. -Alex P.S. Let me know if this message is sent incorrectly (I scrolled down to the bottom of the text box to type this, as opposed to writing the message at the top of the text box. I am guessing this is what is meant by "top-posting."). ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Regular expressions: findall vs search
I'm a bit confused about extracting data using re.search or re.findall. Say I have the following code: tuples = re.findall(r'blahblah(\d+)yattayattayatta(\w+)moreblahblahblah(\w+)over', text) So I'm looking for that string in 'text', and I intend to extract the parts which have parentheses around them. And it works: the variable "tuples", which I assigned to get the return of re.findall, returns a tuple list, each 'element' therein being a tuple of 3 elements (which is what I wanted since I had 3 sets of parentheses). My question is how does Python know to return just the part in the parentheses and not to return the "blahblah" and the "yattayattayatta", etc...? The 're.search' function returns the whole thing, and if I want just the parentheses parts, I do tuples.group(1) or tuples.group(2) or tuples.group(3), depending on which set of parentheses I want. Does the re.findall command by default ignore anything outside of the parentheses and only return the parentheses as a grouping withing one tuple (i.e., the first element in "tuples" would be, as it is, a list comprised of 3 elements corresponding respectively to the 1st, 2nd, and 3rd parentheses)? Thank you for reading. -Alex ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Calling a function does not return what I want it to return
I have this little program that is supposed to calculate how many diagonals a polygon of x sides has, but it does not return what I have in the "return" part of the function when I call it. Here is the code: def num_diag(var): ans = 0 if var <= 3: print("No diagonals.") else: for i in range(num_sides - 3): ans = ans + i return (((var - 3)*2) + ans) num_sides = (int(raw_input("Enter sides: "))) num_diag(num_sides) Any suggestions as to what is going on? When I run it, it prompts me for the number of sides, and that's it. Thanks. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calling a function does not return what I want it to return
On Thu, Jul 19, 2012 at 4:21 PM, Dave Angel wrote: > On 07/19/2012 06:58 PM, Alexander Q. wrote: > > I have this little program that is supposed to calculate how many > diagonals > > a polygon of x sides has, but it does not return what I have in the > > "return" part of the function when I call it. Here is the code: > > > > def num_diag(var): > > ans = 0 > > if var <= 3: > > print("No diagonals.") > > else: > > for i in range(num_sides - 3): > > ans = ans + i > > > > return (((var - 3)*2) + ans) > > > > num_sides = (int(raw_input("Enter sides: "))) > > num_diag(num_sides) > > > > > > Any suggestions as to what is going on? When I run it, it prompts me for > > the number of sides, and that's it. > > Thanks. > > > > > > You never use the return value. Try assigning it, and printing it. > > result = num_diag(num_sides) > print("final answer=", result) > > -- > > DaveA > > That did it- thanks Dave! -Alex ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Newline question
I'm following the tutorial from python.org ( http://docs.python.org/tutorial/introduction.html) and am having a few indiscrepancies regarding the new line command. The tutorial says that this code hello = "This is a rather long string containing\n\ several lines of text just as you would do in C.\n\ **Note that whitespace at the beginning of the line is\ significant." should yield this output: This is a rather long string containing several lines of text just as you would do in C. Note that whitespace at the beginning of the line is significant. When I run it in the interpreter however, I get the following output: 'This is a rather long string containing\nseveral lines of text just as you would do in C.\nNote that whitespace at the beginning of the line is significant.' The interpreter is not reading the "\n" as new lines but is instead printing them. If I just type something like hello = "This is a rather long string containing \ several lines of text." the output is all on one line, like this: "This is a rather long string containing several lines of text." So I know how to combine code that spans multiple lines to be outputted on one line, but I do not know how to make a newline appear in the output upon command (on account of the interpreter not reading the \n). Any suggestions as to why my output varies from the output in the tutorial? I am running a 2.7 version of Python, btw, and the tutorial is running a higher version I believe (3. something). Thank you. -Alex ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Newline question
On Fri, Aug 3, 2012 at 1:40 PM, Jerry Hill wrote: > On Fri, Aug 3, 2012 at 4:18 PM, Alexander Q. wrote: > > I'm following the tutorial from python.org > > (http://docs.python.org/tutorial/introduction.html) and am having a few > > indiscrepancies regarding the new line command. > > > > The tutorial says that this code > > > > hello = "This is a rather long string containing\n\ > > several lines of text just as you would do in C.\n\ > > Note that whitespace at the beginning of the line is\ > > significant." > > > > should yield this output: > > > > This is a rather long string containing > > several lines of text just as you would do in C. > > Note that whitespace at the beginning of the line is significant. > > You left out the other line of code in the tutorial, which says you > need to do print(hello) to the the output that is described. Did you > do that? If so, it should work fine. If not, what did you do > instead? If you just typed: > > >>>hello > > at the interpreter prompt, then you are actually seeing the equivalent > of print(repr(hello)), instead of print(hello). > > Can you copy and paste your session for us? > > Jerry > That was it Jerry- when I typed in "print hello" instead of just "hello", the output was exactly like the one in the tutorial. Alternatively, I could accomplish the same type of output by using triple quotes around the same text, except that I would have to format it manually if I want it to come out looking the same way as it did when using "\n" in the previous example? Thanks again for your help. The way I understand it from your explanation is that "hello" does a literal output of everything typed without processing the escape backslashes, while "print hello" does process them. -Alex ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Newline question
On Fri, Aug 3, 2012 at 2:09 PM, Alexander Q. wrote: > > > On Fri, Aug 3, 2012 at 1:40 PM, Jerry Hill wrote: > >> On Fri, Aug 3, 2012 at 4:18 PM, Alexander Q. >> wrote: >> > I'm following the tutorial from python.org >> > (http://docs.python.org/tutorial/introduction.html) and am having a few >> > indiscrepancies regarding the new line command. >> > >> > The tutorial says that this code >> > >> > hello = "This is a rather long string containing\n\ >> > several lines of text just as you would do in C.\n\ >> > Note that whitespace at the beginning of the line is\ >> > significant." >> > >> > should yield this output: >> > >> > This is a rather long string containing >> > several lines of text just as you would do in C. >> > Note that whitespace at the beginning of the line is significant. >> >> You left out the other line of code in the tutorial, which says you >> need to do print(hello) to the the output that is described. Did you >> do that? If so, it should work fine. If not, what did you do >> instead? If you just typed: >> >> >>>hello >> >> at the interpreter prompt, then you are actually seeing the equivalent >> of print(repr(hello)), instead of print(hello). >> >> Can you copy and paste your session for us? >> >> Jerry >> > > That was it Jerry- when I typed in "print hello" instead of just "hello", > the output was exactly like the one in the tutorial. Alternatively, I could > accomplish the same type of output by using triple quotes around the same > text, except that I would have to format it manually if I want it to come > out looking the same way as it did when using "\n" in the previous example? > Thanks again for your help. The way I understand it from your explanation > is that "hello" does a literal output of everything typed without > processing the escape backslashes, while "print hello" does process them. > > -Alex > > Yes, thanks Matt- I realized my mistake soon after sending the email. -Alex ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Documentation
On Jan 6, 2013, at 22:48, Ed Owens wrote: > I have been working my way through Chun's book Core Python Applications. > > In chapter 9 he has a web crawler program that essentially copies all the > files from a web site by finding and downloading the links on that domain. > > One of the classes has a procedure definition, and I'm having trouble finding > documentation for the functions. The code is: > > def parse_links(self): > 'Parse out the links found in downloaded HTML file' > f = open(self.file, 'r') > data = f.read() > f.close() > parser = HTMLParser(formatter.AbstractFormatter( > formatter.DumbWriter(cStringIO.StringIO( > parser.feed(data) > parser.close() > return parser.anchorlist > > HTMLParser is from htmllib. > > I'm having trouble finding clear documentation for what the functions that > are on the 'parser =' line do and return. The three modules (htmllib, > formatter, & cStringIO are all imported, but I can't seem to find much info > on how they work and what they do. What this actually does and what it > produces is completely obscure to me. > > Any help would be appreciated. Any links to clear documentation and examples? > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor Hi Ed, maybe this helps: http://docs.python.org/2/library/htmllib.html A___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to make a python script run on startup
There is a startup folder, usually on the start menu, you can add the script to. --ame On Apr 9, 2013, at 4:20, daedae11 wrote: > On Windows, how to make a python script run on startup? > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Mastering the fundamentals
Hello Tutorians, I've just recently acquired "Learning Python", and I must state that it is a fairly thorough book. However it seems as if I am learning at a very slow pace, so my question is, as far as setting a goal to master the basics, where should I be within a years time? Assuming I spend at least 2 hours of actual coding time per day. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] python 3.3 split method confusion
Hello fellow tutors, I am curious to know why the split() method does not output the arbitrary delimiter that is passed as an argument? For example: string1 = "this,is,just,another,string" print(string1.split(",")) I understand the the above code simply states, "break at every ' , ' ". But why is the delimiter not printed as well? -- Regards, Christian Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python 3.3 split method confusion
Thank you for clarifying my inquiry. I was just unable to find the reason as to why the built-in excludes the delimiter from the outpu. On Sat, Jan 4, 2014 at 9:25 AM, Alan Gauld wrote: > On 04/01/14 14:10, Christian Alexander wrote: > > I am curious to know why the split() method does not output the >> arbitrary delimiter that is passed as an argument? For example: >> > > Because in most cases you don't want it and would have to strip > it off each element manually after the event. > > I suppose they could have had a preserve parameter with a > default value of False for the few cases where you want to > keep it. > > But in the majority of cases split is used where we read a line > of input from a data file where the data fields are separated > by some arbitrary character, usually comma, tab or pipe. The > important bit is the data not the separator. > > > -- > 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 > -- Regards, Christian Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python 3.3 split method confusion
That makes total sense now. I was just curious as to why it didn't output the arbitrary delimiter in the list, or if there was a specific reason for it. On Sat, Jan 4, 2014 at 10:03 PM, Danny Yoo wrote: > One of the common cases for split() is to break a line into a list of > words, for example. > > # > >>> 'hello this is a test'.split() > ['hello', 'this', 'is', 'a', 'test'] > # > > The Standard Library can not do everything that we can conceive of as > being useful, because that set is fairly large. > > If the Standard Library doesn't do it, we'll probably need to do it > ourselves, or find someone who has done it already. > > > ## > >>> def mysplit(s, delim): > ... start = 0 > ... while True: > ... index = s.find(delim, start) > ... if index != -1: > ... yield s[start:index] > ... yield delim > ... start = index + len(delim) > ... else: > ... yield s[start:] > ... return > ... > >>> list(mysplit("this,is,a,test", ",")) > ['this', ',', 'is', ',', 'a', ',', 'test'] > ## > -- Regards, Christian Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Interactive escape sequences
Hello Tutorians, Why does the interactive prompt not recognize escape sequences in strings? It only works correctly if I use the print function in python 3. >>> "Hello\nWorld" "Hello\nWorld" -- Regards, Christian Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Understanding Classes
Hello Tutorians, Looked all over the net for class tutorials Unable to understand the "self" argument Attempting to visual classes I have searched high and low, for easy to follow tutorials regarding classes. Although I grok the general concept of classes, I am unable to visually understand what exactly "self" does, or why it is even necessary. It seems very "magic" to me. Also I am having the most difficult with the "__init__()" method in classes, and why that is also required. Keep in mind that I am a visual person (maybe I should have been a graphic designer), therefore most programming concepts flow irritatingly slow for me. -- Regards, Christian Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Understanding Classes
I would first like to state two things, those being that I am a horrible writer as well as explaining things, but Ill try my absolute best. Everything python is an object. Strings, integers, lists, so on and so forth. In regards to classes and their relativity towards objects, I am at complete standstill. However, I understand that classes are parallel to that of a blueprint, but that is unfortunately where the buck stops. On Sun, Jan 19, 2014 at 6:50 PM, Alan Gauld wrote: > On 19/01/14 21:59, Christian Alexander wrote: > >> Looked all over the net for class tutorials >> Unable to understand the "self" argument >> Attempting to visual classes >> > > If you read my OOP tutorial there is a section there specifically about > self. > > And the v3 tutor includes an introduction to the formal visualisation > technique for OOP called UML. The diagrams illustrating the designs may > help. > > http://www.alan-g.me.uk/l2p/tutclass.htm > > > I have searched high and low, for easy to follow tutorials regarding >> classes. Although I grok the general concept of classes, >> > > Do you also grok the concept of objects? > Classes on their own are fairly useless (unless you are using Java) > it is only when you create a universe of objects from those classes that > they become useful. > > If you can repeat to us your understanding of classes and their > relationship with objects that will help us understand your > level and shape our responses accordingly. > > > to visually understand what exactly "self" does, or why it is even >> necessary. It seems very "magic" to me. >> > > When you define a class you define the data (attributes) that > the class instances will have. Each instance will have a copy of the data > defined in the __init__() method. > You also define a set of operations or methods that are associated > with the class. Those methods are shared by the instances. > > Note the difference. Instances get a copy of the attributes > but they all share the methods. > > Thus when you invoke a method on an instance the instance relays that call > to the class. For the class to know which instance is being operated on, > and for the method to be able to access the correct instance's data it > needs a reference to the instance. That reference > is typically called 'self' or 'this'. (In some languages it's fixed > but in Python self is only a convention, you can use any name you like). > > You can make the call to the class explicit and it will still work. > See below: > > # define a class > class MyClass: > def __init__(self,x): self.x = x > def myMethod(self): print(self.x) > > # create some instances > ObjA = MyClass(2) > ObjB = MyClass(4) > ObjC = MyClass(6) > > # send some messages/call methods > objA.myMethod() # call from the instance > MyClass.myMethod(ObjB) # call explicitly to the class > objC.myMethod() # direct again > > All 3 calls do the same thing except the middle one > passes the object identifier directly to the class > whereas the first and last both do that internally > within the object structure. > > > difficult with the "__init__()" method in classes, >> > > and why that is also required. > > It is not *required* as such. You can create a class > without an init but it's unusual. > > When you create an instance of a class it creates a > data structure in memory referenced by the name of > the instance. But that structure is empty, it has > no data. So to populate the data for the instances > you must initialize it. That's what __init__() does. > It takes the arguments you provide and applies them > to the instance along with any static data definitions > you may define. > > In the example we create an instance variable, x, > within the instances and assign the value of the > argument passed to init. Like any other method the > actual code lives in the class so we could initialize > it by calling init like so: > > MyClass.__init__(objC, 66) > > which is almost the same as doing: > > objC = MyClass(66) > > The difference is that the first case requires the object ObjC > to already exist, the second example creates a new instance and > then calls init on that instance. > > > Keep in mind that I am a visual person (maybe I should have >> been a graphic designer), therefore most programming concepts flow >> irritatingly slow for me. >> > > Most programming concepts have visual representations, > its just that program code being text tends to lead programmers > to be verbally based. But algorithms, state machin
Re: [Tutor] Understanding Classes
Alan, The concept and purpose of classes is starting to sink in a little bit, but I still haven't had my "Ah-ha" moment yet. I just can't seem to visualize the execution of classes, nor am I able to explain to myself how it actually works. For example: class Person: def __init__ (self, name, age):# is self just a placeholder for an arbitrary object? How does __init__ actually work? self.name = name # why assign name to self.name variable? self.age = age # same as previous def salute (self): # again with the self print ("Hello, my name is " + self.name + " and I am " + str(self.age) " years old.") On Mon, Jan 20, 2014 at 4:20 PM, spir wrote: > On 01/19/2014 10:59 PM, Christian Alexander wrote: > >> Hello Tutorians, >> >> Looked all over the net for class tutorials >> Unable to understand the "self" argument >> Attempting to visual classes >> >> I have searched high and low, for easy to follow tutorials regarding >> classes. Although I grok the general concept of classes, I am unable to >> visually understand what exactly "self" does, or why it is even necessary. >> It seems very "magic" to me. Also I am having the most difficult with >> the >> "__init__()" method in classes, and why that is also required. Keep in >> mind that I am a visual person (maybe I should have been a graphic >> designer), therefore most programming concepts flow irritatingly slow for >> me. >> > > Imagine that for an app you had to define 2 persons p1 & p2 (maybe game > characters for instance). In an imaginary programming language, a > definition of p1 could look like this: > > p1 = {name="Maria", age=33} # no good python code > > This would be a composite piece of data, made of 2 fields (attributes, > properties...). In python there is no such generic type Object or Composite > to which such data as p1 could belong. You must define a custom type > (class) for them, eg: > > class Person: pass > > Now, you can have p1 of type Person, which is written as if you would call > the type Person, like a func, to make a new person (this is close to what > happens): > > p1 = Person() > > Then, one can define fields on it: > > p1.name = "Maria" > p1.age = 33 > print(p1.name, p1.age) > > We could do the same thing for p2: > > p2 = Person() > p2.name = "paulo" > p2.age = 22 > print(p2.name, p2.age) > > Now, say persons are supposed to do things, and all can do the same > things. To define something all persons can do, you would define it on > their class (this is the second purpose of a class), eg: > > class Person: > def salute (self): > print ("Hello, my name is " + self.name + > " and I am " + str(self.age) " years old.") > > As you can see, this method uses the attributes 'name' & 'age' we manually > defined on both p1 & p2. Then, how does the method, which is defined on the > type, not on individual objects, know where to find these attributes? You > are right to say there is some magic at play here. Let us use the method > first, before explaining: > > p1.salute() > p2.salute() > > [Copy-paste & run all this code.] On the first call, we ask the method > 'salute' to operate on p1, and it writes p1's name & age. Same for p2. > Inside the method, the attributes are searched on the weird param called > 'self'. This is just what happens: when calling a method, the object on > which it operates is assigned to the parameter self. 'self' is just a name > for the-object-on-which-this-method-operates-now. When it operates on p1, > self is p1, thus attributes are searched on p1; same for p2. We need some > placeholder because the method is defined on the type and works for any > object of this type (any "instance"). [We can define a method on p1 which > works on p1 only. Maybe try it.] > > Finally, if we define a whole range of persons that way, it is annoying to > set all attributes manually. We could define a method, say 'def_attrs', to > be called at startup. But python has a specially dedicated method for that, > which we don't even need to call explicitely, named '__init__'. We will use > it to set person attributes: > > class Person: > def __init__ (self, name, age): > self.na