Re: [Tutor] beginning to code
> unindent does not match any outer indention level Means that your Intendentaion is not proper. You should align your print statement and rest to the same level as if statement. Use a proper editor that supports Python Syntax. On Sun, Sep 10, 2017 at 4:32 AM, Elmar Klein wrote: > Hi there, > > im starting to learn how to code (bougt me the "automate the boring stuff > with phyton" book). > > And im not going anywhere with a code sample using the "continue" > statement. > > The code i should try is as following: > > while True: > print ('who are you') > name = input () > if name != 'bert': > continue > print ('hi, joe. pwd?') > pwd = input () > if pwd == 'sword': > break > print ('access granted') > > But everytime this produces an error (unindent does not match any outer > indention level) in the "print ('hi, joe. Pwd?')" sentence. > > What am i doing wrong? > > Greetings > > kerbi > > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What is URL to online Python interpreter?
On Thu, Dec 17, 2009 at 09:32:44PM -0800, Benjamin Castillo wrote: > What is URL to online Python interpreter? Google could have helped you too. Anyways, http://shell.appspot.com/ -- Senthil ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib
On Mon, Dec 07, 2009 at 08:38:24AM +0100, Jojo Mwebaze wrote: > I need help on something very small... > > i am using urllib to write a query and what i want returned is 'FHI=128%2C128& > FLO=1%2C1' > The way to use urllib.encode is like this: >>> urllib.urlencode({"key":"value"}) 'key=value' >>> urllib.urlencode({"key":"value","key2":"value2"}) 'key2=value2&key=value' For your purpses, you need to construct the dict this way: >>> urllib.urlencode({"FHI":'128,128',"FHO":'1,1'}) 'FHO=1%2C1&FHI=128%2C128' >>> And if you are to use variables, one way to do it would be: >>> x1,y1,x2,y2 = 1,1,128,128 >>> fhi = str(x2) + ',' + str(y2) >>> fho = str(x1) + ',' + str(y1) >>> urllib.urlencode({"FHI":fhi,"FHO":fho}) 'FHO=1%2C1&FHI=128%2C128' -- Senthil ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] saving output data in a file
On Fri, Dec 04, 2009 at 01:13:42PM +0530, Prasad Mehendale wrote: > I am a beginner. I want to save the output data of the following programme in > a file through the programme. Please suggest me the way. I am using Python > 2.3.3 on mandrake linux 10 and using "Idle" to save the output to a file > presently. To save the output to a file, you have a open a file object and write to it. When you are done, just close it. If your program, open a fileobj somewhere on the top. fileobj = open('dc-generator-output.txt','w') And where you put the print statement, replace it with fileobj.write(" ") # Within in the " " the output which you want to put. One strategy would be create a string in place of your print and write the string. For eg. Instead of print '(Pole*RPM) product for various values of conductors/slot is: \n', polerpm You will do msg = '(Pole*RPM) product for various values of conductors/slot is: \n', polerpm fileobj.write(msg) And in the end, close the fileobj. fileobj.close() -- Senthil Flee at once, all is discovered. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What language should I learn after Python?
On Tue, Oct 06, 2009 at 03:39:36PM -0400, Mark Young wrote: > I'm now fairly familiar with Python, so I'm thinking about starting to learn a > second programming language. The problem is, I don't know which to learn. I You have already got a lot of healthy advice in this thread. I would like to suggest that you might take up some project which involves a lot of python and little bit of a different language (Java Script, if it's a webbased project). In that way, you will hone your python skills and additionally start learning the new language. Just look around at Google App Engine and see if you can think of any project (simple one), and try implmenting it. You might end up using JavaScript/HTML. I am learning www.alice.org after Python. It is too much fun! -- Senthil Be careful of reading health books, you might die of a misprint. -- Mark Twain ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to make the difference between binary and text files ?
Hello Dominique, On Sat, Apr 4, 2009 at 6:07 AM, Dominique wrote: > I am developing a very small multi-platform app to search for a specific word > or > expression in files located in a drive or directory. > So I need to open files to search for the word. > > I read that opening a binary file as a text file (open(filename, 'r')) may > corrupt the file. First of all, I doubt if reading a file in text format would cause any harm. Writing may screw things up. Secondly, determining the type of file is based on heuristics and most often determined by reading a chunck of the file. I found the following recipe, that could be useful to you: http://code.activestate.com/recipes/173220/ -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to send an email using Python
Hello Samuel, When sending through smtp.gmail.com you might need to starttls() and do a login() before sending. >>> import smtplib >>> headers = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" %(from,to,subject) >>> message = headers + "Hello, How are you?" >>> mailserver = smtplib.SMTP('smtp.gmail.com') >>> mailserver.ehlo() >>> mailserver.starttls() >>> mailserver.login('username','password') >>> mailserver.sendmail(from,to,message) As I try it now, startls() was giving me a message " reply: '454 TLS not available due to temporary reason\r\n'" - As the error message says, it could be temporary. Try it at your end and report if you succeed. Thanks, Senthil On Tue, Mar 10, 2009 at 4:41 PM, Samuel Avinash wrote: > Hi, > Can anybody tell me how to send an email to a recipient using Python > I am trying to send an email using Gmail > I create an instance of smtplib and use : > x=smtplib.SMTP(sever,port) > and then > x.login(user,pwd) > I try to send the email using > x..sendmail(SENDER, RECIPIENTS, msg) > But I get the following error > Traceback (most recent call last): > File "C:UsersAvisDesktopMail.py", line 13, in > session = smtplib.SMTP(smtpserver,port) > File "C:Python26libsmtplib.py", line 239, in __init__ > (code, msg) = self.connect(host, port) > File "C:Python26libsmtplib.py", line 295, in connect > self.sock = self._get_socket(host, port, self.timeout) > File "C:Python26libsmtplib.py", line 273, in _get_socket > return socket.create_connection((port, host), timeout) > File "C:Python26libsocket.py", line 498, in create_connection > for res in getaddrinfo(host, port, 0, SOCK_STREAM): > socket.gaierror: [Errno 11001] getaddrinfo failed > > This is in Windows Vista and I am trying to connect to "smtp.gmail.com" with > port 465 > ___ > Tutor maillist - tu...@python.org > http://mail.python.org/mailman/listinfo/tutor > > -- -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] if inside if help python
> I have question if we make if statement inside if like cprogramming below > how to do in python Indentation is the key here. It is very simple. x=1 y=2 if x == 1: print "inside first if" if x == 2: print "inside second if" -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] glob in order of the file numbers
2009/3/7 Emad Nawfal (عماد نوفل) : > import glob > for path in glob.iglob("*.temp"): > infile = open(path) > for line in infile: > print line.strip() import glob files = sorted(glob.glob("*.temp")) for each in files: print open(each).read() Note couple of things: - glob.glob - sorted to arranged in order. - just read() the fhandle to read the contents. -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Convert XML codes to "normal" text?
On Wed, Mar 4, 2009 at 11:13 AM, Eric Dorsey wrote: > I know, for example, that the > code means >, but what I don't know is > how to convert it in all my data to show properly? I Feedparser returns the output in html only so except html tags and entities in the output. What you want is to Unescape HTML entities ( http://effbot.org/zone/re-sub.htm#unescape-html ) import feedparser import re, htmlentitydefs def unescape(text): def fixup(m): text = m.group(0) if text[:2] == "": # character reference try: if text[:3] == "": return unichr(int(text[3:-1], 16)) else: return unichr(int(text[2:-1])) except ValueError: pass else: # named entity try: text = unichr(htmlentitydefs.name2codepoint[text[1:-1]]) except KeyError: pass return text # leave as is return re.sub("?\w+;", fixup, text) d = feedparser.parse('http://snipt.net/dorseye/feed') x=0 for i in d['entries']: print unescape(d['entries'][x].title) print unescape(d['entries'][x].summary) print x+=1 HTH, Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Formatting
On Wed, Feb 25, 2009 at 10:37 AM, prasad rao wrote: > > licenseRe = re.compile(r'\(([A-Z]+)\)( No. (\d+))?') Change that to: licenseRe = re.compile(r'\(([A-Z]+)\)\s*(No.\d+)?') It now works. Thanks, Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Exercises for Classes and OOP in Python
Hello, I am looking for a good material that would provide exercises (and possibly solutions to demo exercises) that illustrates the Object Oriented Programming constructs in Python. Can pointers? TIA, Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] urllib unquote
On Tue, Feb 17, 2009 at 1:24 PM, Norman Khine wrote: > Thank you, but is it possible to get the original string from this? What do you mean by the original string Norman? Look at these definitions: Quoted String: In the different parts of the URL, there are set of characters, for e.g. space character in path, that must be quoted, which means converted to a different form so that url is understood by the program. So ' ' is quoted to %20. Unquoted String: When %20 comes in the URL, humans need it unquoted so that we can understand it. What do you mean by original string? Why are you doing base64 encoding? And what are you trying to achieve? Perhaps these can help us to help you better? -- -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Keeping Dictonary Entries Ordered
On Thu, Feb 12, 2009 at 2:55 PM, Alan Gauld wrote: > But you need to have an order that will work with sorted(). > Its not just the order you add items to the dict. And yes algorithmically, there is No Requirement or I should say a good Use Case for a Dict to have sorted keys. More we work with dictionaries. we will understand this rationale better. -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passing unknown no of arguments
On Thu, Feb 5, 2009 at 2:27 PM, Alan Gauld wrote: > In general you can't. You would need to have a Python interpreter > in your browser. Alan, I think he was referring to CGI programming. Given the nature of his first question. Well continuing the discussion further, I saw a post by Bret Cannon on the possibility of Firefox 4 supporting Python. -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passing unknown no of arguments
On Thu, Feb 5, 2009 at 1:37 PM, amit sethi wrote: > How do you pass arguments of unknown no. of arguments to a function. You use * operator ( indirection) in the function definition for arguments and you pass the variable number of number arguments as a list. For e.g. >>> def foo(*args): ... print args ... >>> foo(1,2,3,4,5,6) (1, 2, 3, 4, 5, 6) >>> foo(1,2,3) (1, 2, 3) >>> > Also how can i run my python scripts in a web browser. What you are asking for is Python CGI programming. Look out for chapters for Alan's book. I think he has covered from the basics. Or just start here: pytute.blogspot.com/2007/05/python-cgi-howto.html You will write a simple script like #!/usr/bin/env python print "Content-Type: text/html\n" print "Hello, World" Give permissions chmod +rw to the script and put it in your web-server's cgi-bin/ directory and invoke the python file. The result will be displayed in the browser. -- Senthil http://uthcode.sarovar.org ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] cube root
On Mon, Jan 19, 2009 at 12:11 PM, Brett Wilkins wrote: > Hey Colin, > What you're running into here is the limited accuracy of floating point > values... Here the Python Documentation mentioning about the inherent limitations in dealing with floating point numbers: http://docs.python.org/tutorial/floatingpoint.html -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Best Python3000 Tutorial for Beginner
On Sun, Jan 18, 2009 at 8:34 AM, Ian Egland wrote: > Hello all, I just joined this mailing list. > > I am a beginner to programming in general and would really appreciate a > tutorial for Python3000 that at least covers the basics. I have tried Hello Ian, That is a nice reason to get started with a language. However, you have to remember that Python 3.0 is not a new language at all. It is just a backwards impatible release of the original almighty pyhon, which just tends to increase its strength and clean its design further. I am not at all surprised that you did not find any beginner Python 3.0 tutorial. It might be coming out soon, but the curretly people migrating to Python 3.0 are ones who already know python 2k well. So, for your purposes I would suggest the following. 1) Get Beginner Python tutorial. (See Alan's tutorial in this mailing list and also google for A Byte of Python) 2) Read and understand the language well. Get comfortable upto a point where you can differentiate between string, unicode and bytes. I should warn you that it might take months' time. and now you can read this very beginner friendly introduction to Python 3k. http://www.comp.leeds.ac.uk/nde/papers/teachpy3.html Thanks, Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Corpora
On Fri, Jan 16, 2009 at 9:11 AM, Ishan Puri wrote: > Hi, > I was wondering if anyone could tell me where I can get corpora > containing IMs, or blogs or any internet communication? This is kind of www.google.com And for IM's specifically, you can look at "Alice Bot" Project, the corpus will be in structured format and you might end up using python to parse it ( and your question becomes relevant to this list :) ) -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 2 & 4 or more spaces per indentation level..
On Thu, Jan 15, 2009 at 06:57:09PM -0700, Eric Dorsey wrote: >Working in IDLE on Windows Vista, I have one program that I set to have >2 character spacing (due to the levels of if's and while's going on -- >later my brother called this a bit of a code smell, ie. logic shouldn't >go that deep, it should be broken out into separate functions instead. Your brother is right. Logic should not go deep and moreover the screen width not enough even with 2 space indentation gives a not-so-good picture too. >Thoughts on that are welcome to, do any of you feel logic should only >go so many layers deep?), and my editor defaults to 4 (Which I believe >is the standard according to PEP 8) Thats the way to approach. Follow PEP8. >they used a different spacing than you, is there a simple/good/smart >way to get it all back to the 4 spacing default? Or if for example I Rule #0 is Never mix tabs and spaces. Rule #1 is use a standard spacing through out the code. And when copying from a certain space-setting indentation to another, the modular script will still work fine. You can use some global find/replace mechanism to do suit your setting. For eg. I remember doing :%s/\ \ /\ \ \ \ /g OR you can also run your code through pyindent or python code beautifier (Google for it, you might find one). But after using the beautifier under these situations, just rely on your eyes to do a quick check if the logic has not gone awry ( which rarely does, but still I would believe myself more than the tool). -- Senthil http://uthocode.sarovar.org ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] single key ordered sequence
> Also, how to practically walk in reverse order in a list without > copying it (e.g. items[::-1]), > especially if i need both indexes and items (couldn't find with > enumerate()). > Are you looking for reversed()? The way you are doing it is probably OK. But it can be simplified thus: keys = [] target = [] for item in reversed(items): if not item[0] in keys: keys.append(item[0]) target.append(item) print target If this is not what you wanted,then I have misunderstood your requirement and just based it on your code. Thanks, Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python3.0 and Tkinter on ubuntu 8.10 HOWTO
On Wed, Jan 14, 2009 at 03:38:20PM -0500, Vern Ceder wrote: > Since there was some interest in the question of how to get a full > Python 3.0, including Tkinter and IDLE, compiled on Ubuntu Intrepid > 8.10, I've written up what I've done and posted it at > http://learnpython.wordpress.com/2009/01/14/installing-python-30-on-ubuntu/ > Good explaination! You can also make a note about make fullinstall, which will make Python 3.0 as the default And also mention about python binary being present as python2.5,python2.6 and python3.0 when more than one version is installed. Thanks, Senthil -- Senthil Kumaran O.R. http://uthcode.sarovar.org ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] eval and floating point
On Thu, Jan 15, 2009 at 9:42 AM, Bill Campbell wrote: > Python does the Right Thing(tm) when dividing two integers, > returning an integer result. > Unless it is python 3k, in which integer division (single /) can result in float. Because int is a long by default. :-) -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] NLTK
> Ishan Puri wrote: > Hi, > I have download NLTK for Python 2.5. It download automatically to > C:\Program Files\Python25\libs\site-packages\nltk. When I try to open a > module in python, it says that no such module exists. What do I need to do? There are ways to install the module in the site-packages. Just downloading and copying to site-packages may not be enough. After you have downloaded the NLTK page, extract it to a separate directory, and find a file called setup.py If it is present, do python setup.py install That sould do. If setup.py is not present, locate README.txt and follow the instructions. Even after following the instructions, if you get any error message, copy/paste the error message here so that we would be able to assist you better. -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Thought of some other things.
On Feb 6, 2008 11:38 PM, Timothy Sikes <[EMAIL PROTECTED]> wrote: > > First off, I was running my script from my flash drive-That could have > caused something. Next, I have possible found something IN the > location where I ran the script, I found a pic_db.bat with stuff in it... It > still doesn't explain why the program crashed, but it does explain why I > didn't think it was doing anything. Your question is unclear, Timothy. Running from the flash drive is not going to cause your program to crash. The interpreter is in the PATH of your computer and you can run your program from flash drive, cd or from the floppy drive. pic_db.bat could be anything. Google for it and verify if it is not a virus. Paste the error message you received for more specific response. Thanks, -- -- O.R.Senthil Kumaran http://phoe6.livejournal.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor