Re: [Tutor] Fraction - differing interpretations for number and string - presentation
> > Is this "inaccurate"? Well, in the sense that it is not the exact true > mathematical result, yes it is, but that term can be misleading if you > think of it as "a mistake". In another sense, it's not inaccurate, it is > as accurate as possible (given the limitation of only having a certain > fixed number of bits). > -- > Steve > --- Understood about the quondam inexactness of floating point bit representation. I was just wondering why the different implementation of representing it when using Fraction(float) as opposed to using Fraction(string(float)). In terms of user presentation, the string usage has smaller numbers for the ratio, so it would be more understandable and should, I assume, be chosen for GUI display. -- Jim The Paleo diet causes Albinism ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fraction - differing interpretations for number and string - presentation
The whole point of the discussion is that this is *not* a presentation issue. Fraction(1.64) and Fraction("1.64") *are* two different numbers because one gets constructed from a value that is not quite 1.64. Wolfgang Maier -- So the longer numerator and denominator would, indeed, be more accurate if used in certain calculations rather than being normalized to a float - such as in a Fortran subroutine or perhaps if exported to a machine with a longer bit-length? That's mainly what I was interested in - if there is any usable difference between the two results. Jim The Paleo diet causes Albinism ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] sample dictionairies
Where could I download Python sample dictionaries on different subjects. They're hard to type and I can only do small, limited ones to practice with. -- Jim The probability of a piano falling on my head is 50%. After it falls on my head the probability is 100%. My confidence in the piano hitting my head has increased. This is Bayesian statistics in a nutshell. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sample dictionairies
For randomly generating data which look like addresses, I use: > http://www.generatedata.com/ > > While it has 'export to programming language' as a feature, Python isn't > one of the supported languages. Which is fine. It can export into comma > separated values, and writing a Python program to construct a dictionary > from comma separated values is easy. > > Laura > That's a great source, and I can generate dictionaries using the other advice. If you don't request comma delimited, each record per line has | as a field delimiter, so making big dicts was easy. Naturally, I tried emailing one of the addresses - aliq...@nunc.org - but it appears to be dead ;') Come to think of it, since I used | as a delimiter, what happens if you generate a CSV file from data that already has commas in the text? -- Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] bin to dec conversion puzzlement
I can't seem to get my head around this 'simple' book example of binary-to-decimal conversion, which goes from left to right: B = '11011101' I = 0 while B: I = I * 2 + int(B[0]) B = B[1:] print(I) >>> 221 My thought was to go from right to left, multiplying digits by successive powers of two, and adding, like so: B = '11011101' sum = 0 for exp, num in enumerate(reversed(B)): sum += int(num) * 2**exp print(sum) >> 221 Both methods work but I just can't see how the first one does. Am I missing something obvious here? -- Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sample dictionairies
> Which is why you should use the csv module to work with csv files, > it knows how to deal with these various exceptional cases. > -- > Alan G > I should have known to simply try importing csv. Must-remember-batteries-included ;') -- Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] bin to dec conversion puzzlement
The key is that the result gets multiplied by 2 each time > so for an N bit number the leftmost digit winds up being > effectively 2**N, which is what you want. > > Alan G Ah, the light dawns once it was restated. It would be even simpler if you could multiply each element of the binary number by it's respective power of two, and sum them all at once. I hear Py 3.5 will have vector abilities. I wonder it if would do something like that. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] enhanced subtration in an exponent
Why does the compiler choke on this? It seems to me that the enhanced subtraction resolves to a legitimate integer in the exponent, but I get a syntax error: B = '11011101' sum = 0 start = len(B) for char in B: sum += int(char) * 2**(start -= 1) ## syntax error print(sum) -- Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] calling a method directly
Is there any difference between these two since they give the same result, and when is the second preferred? >>> x = 'ABE' >>> x.lower() 'abe' >>> str.lower(x) 'abe' -- Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] name shortening in a csv module output
I'm trying the csv module. It all went well until I tried shortening a long first name I put in just to exercise things. It didn't shorten. And I also got weird first characters on the header line. What went wrong? import csv allcsv = [] with open('data.txt') as csvfile: readCSV = csv.reader(csvfile, delimiter='|') topline = next(readCSV) topline[0] = topline[0].replace('_', ' ').title() topline[1] = topline[1].replace('_', ' ').title() print("{0:<20s} {1:<20s}".format(topline[0], topline[1])) print('==') for line in readCSV: if len(line[0]) > 40: # problem here - didn't shorten line[0] = line[0][:40] print("{0:<20s} {1:<20s}".format(line[0], line[1])) Original file lines: first_name|last_name|email|city|state or region|address|zip Stewartrewqrhjeiwqhreqwhreowpqhrueqwphruepqhruepqwhruepwhqupr|Dorsey|nec.malesu...@quisqueporttitoreros.com|Cariboo Regional District|BC|P.O. Box 292, 8945 Nulla Avenue|5945 Madonna|Sosa|senectus...@eget.ca|Belford Roxo|Rio de Janeiro|P.O. Box 538, 4484 Sem Avenue|81833 Duncan|Hutchinson|donec.vi...@integer.co.uk|Dublin|Leinster|Ap #847-2344 Feugiat. St.|9222 ... My result: Ï»¿First NameLast Name # odd characters on header line == Stewartrewqrhjeiwqhreqwhreowpqhrueqwphru Dorsey Madonna Sosa Duncan Hutchinson ... -- Jim No comment ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] name shortening in a csv module output
.. > Ï»¿ > > is the UTF-8 BOM (byte order mark) interpreted as Latin 1. > > If the input is UTF-8 you can get rid of the BOM with > > with open("data.txt", encoding="utf-8-sig") as csvfile: > Peter Otten I caught the bad arithmetic on name length, but where is the byte order mark coming from? My first line is plain English so far as I can see - no umlauts or foreign characters. first_name|last_name|email|city|state or region|address|zip Is this an artifact of csv module output, or is it the data from generatedata.com, which looks global? More likely it means I have to figure out unicode ;'( ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] name shortening in a csv module output
> > By relying on the default when you read it, you're making an unspoken > assumption about the encoding of the file. > > -- > DaveA So is there any way to sniff the encoding, including the BOM (which appears to be used or not used randomly for utf-8), so you can then use the proper encoding, or do you wander in the wilderness? I was going to use encoding = utf-8 as a suggested default. I noticed it got rid of the bom symbols but left an extra blank space at the beginning of the stream. Most books leave unicode to the very end, if they mention the BOM at all (mine is at page 977, which is still a bit off ;') ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] name shortening in a csv module output
So is there any way to sniff the encoding, including the BOM (which appears to be used or not used randomly for utf-8), so you can then use the proper encoding, or do you wander in the wilderness? Pretty much guesswork. > Alan Gauld -- This all sounds suspiciously like the old browser wars I suffered while webmastering. I'd almost think Microsoft had a hand in it ;') If utf-8 can handle a million characters, why isn't it just the standard? I doubt we'd need more unless the Martians land. Since I am reading opinions that the BOM doesn't even belong in utf-8, can I assume just using utf-8-sig as my default encoding, even on a non-BOM file, would do no harm? Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Spongebob Pythonpants
I was depressed at the thought of learning unicode, then discovered Python was fun again since I can easily print any ascii art from http://www.chris.com/ascii/ with a multiline print, so long as I replace any backslash with two of them. Spongebob Squarepants was, of course, the obvious first choice. The heck with Tkinter. (Bob is coming out a bit thin in my gmail but looks fine in the REPL.) print(''' .--..--..--..--..--..--. .' \\ (`._ (_) _ \\ .'| '._) (_) | \\ _.')\\ ...---. / |(_.' |/.-\\-. \\ | \\ 0|| ( O| O) | o| | _ | .--..'._.-. | \\ (_) | o -` .-` | |\\ |`-._ _ _ _ _\\ / \\| | `. |_||_| | | o |\\_ \\ | -. .-. |.-. \\ `--..-' O | `.`-' .' _.' .' | `-.-' /-.__ ' .-' .' `-.` '.|='=.='=.='=.='=|._/_ `-'.' `-._ `. |/\\_|`-.' .' ).| '=' '='\\/ '=' | `._.` '---' //___\\ //___\\ || || LGB ||_.-. ||_.-. (_.--__) (_.--__)''') *** Remote Interpreter Reinitialized *** >>> .--..--..--..--..--..--. .' \ (`._ (_) _ \ .'| '._) (_) | \ _.')\ ...---. / |(_.' |/.-\-. \ | \ 0|| ( O| O) | o| | _ | .--..'._.-. | \ (_) | o -` .-` | |\ |`-._ _ _ _ _\ / \| | `. |_||_| | | o |\_ \ | -. .-. |.-. \ `--..-' O | `.`-' .' _.' .' | `-.-' /-.__ ' .-' .' `-.` '.|='=.='=.='=.='=|._/_ `-'.' `-._ `. |/\_|`-.' .' ).| '=' '='\/ '=' | `._.` '---' //___\ //___\ || || LGB ||_.-. ||_.-. (_.--__) (_.--__) >>> -- Jim No comment ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Spongebob Pythonpants
You can save yourself some time and use a raw string: > print(r""" """) > > Timo > > Good point. I'll go to site-packages and change that. I import Bob to cheer myself up as I look at Unicode, which is like forcing a kid to go to Sunday school on a bright Summer day, instead of playing with Python. I wonder if there's a Unicode for Idiots book ;') Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] name shortening in a csv module output
> > Apparently so. It looks like utf_8-sig just ignores the sig if it is > present, and uses UTF-8 whether the signature is present or not. > > That surprises me. > > -- > Steve > > I was looking things up and although there are aliases for utf_8 (utf8 and utf-8) I see no aliases for utf_8_sig, so I'm surprised the utf-8-sig I tried using, worked at all. Actually, I was trying to find the file where the aliases are so I could change it and have utf_8_sig called up when I used utf8, but it appears to be hard-coded. -- Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] sig no matter what
It looks like sig works for any dash, underline combination, and is ignored if there is no BOM: >>> farf = bytes('many moons ago I sat on a rock', encoding='utf8') >>> farf b'many moons ago I sat on a rock' >>> str(farf, encoding="utf_8_sig") 'many moons ago I sat on a rock' >>> str(farf, encoding="utf-8-sig") 'many moons ago I sat on a rock' >>> str(farf, encoding="utf_8-sig") 'many moons ago I sat on a rock' >>> str(farf, encoding="utf-8_sig") 'many moons ago I sat on a rock' -- Jim Then: "Get rich flipping houses, with No Money Down!" Now: "Get rich making the next great app, with No Programming!" There's always a sucker for get-rich-quick schemes. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Making an alias
Actually,. I found the aliases in Lib/encodings/aliases.py and added an alias: >>> deco = bytes("I sure hate apples.", encoding='ubom') >>> deco b'\xef\xbb\xbfI sure hate apples.' >>> Tricky, though - if you don't put a comma at the end of your alias, it breaks Python (or my Pyscripter editor, anyway ;') -- Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Spongebob Pythonpants
Unicode for Idiots indeed, a Python list can always find something better than that :) > > http://www.joelonsoftware.com/articles/Unicode.html > http://nedbatchelder.com/text/unipain.html > > > Mark Lawrence > > Batcheder's looks good. I'm going through it. I tried the Unicode Consortium website at unicode.org, but forget that - I'd rather pull my own teeth than wade through it ;') Jim If you only had one hour left to live, would you spend it on Facebook, Twitter, or Google Plus? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] name shortening in a csv module output
> > > I wouldn't use utf-8-sig for output, however, as it puts the BOM in the > file for others to trip over. > > -- > DaveA Yeah, I found that out when I altered the aliases.py dictionary and added 'ubom' : 'utf_8_sig' as an item. Encoding didn't work out so good, but decoding was fine ;') ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sig no matter what
> See 7.2.3 (aliases) and 7.2.7 (utf_8_sig) in the codecs documentation. > > https://docs.python.org/3/library/codecs.html > The docs don't mention that case is immaterial for aliases, when it usually matters in Python. The actual dictionary entries in aliases.py often differ in case from the docs. For instance, this works: >>> p = bytes("This sure sux", encoding="uTf32") >>> p b'\xff\xfe\x00\x00T\x00\x00\x00h\x00\x00\x00i\x00\x00\x00s\x00\x00\x00 \x00\x00\x00s\x00\x00\x00u\x00\x00\x00r\x00\x00\x00e\x00\x00\x00 \x00\x00\x00s\x00\x00\x00u\x00\x00\x00x\x00\x00\x00' >>> aliases.py # utf_8 codec 'u8': 'utf_8', 'utf': 'utf_8', 'utf8' : 'utf_8', 'utf8_ucs2' : 'utf_8', 'utf8_ucs4' : 'utf_8', 'ubom' : 'utf_8_sig' So of course my favorite is u8 - less typing, and ubom for decoding if I get those funny bytes ;') -- Jim If you only had one hour left to live, would you spend it on Facebook, Twitter, or Google Plus? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Codec lookup, was Re: name shortening in a csv module output
> > Hm, who the heck uses "u8"? I'd rather go with > > >>> encodings.aliases.aliases["steven_s_preferred_encoding"] = "utf_8" > >>> "Hello".encode("--- Steven's preferred encoding ---") > b'Hello' > > ;) > Peter Otten > __ > Or normalize almost any mistyping ;'): >>> encodings.normalize_encoding('utf&&$%##8') 'utf_8' -- Jim If you only had one hour left to live, would you spend it on Facebook, Twitter, or Google Plus? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] REPL format
I'm curious why, when I read and decode a binary file from the net in one fell swoop, the REPL prints it between parentheses, line by line but with no commas, like a defective tuple. I can see breaking lines visually, at \n, but if the parentheses don't mean anything I can't see including them. Or do they mean something I've missed? Also, it's interesting that although HTML is case-free, you have to get the case right for the java server page. getbusesforroute.jsp doesn't work. ?import urllib.request u = urllib.request.urlopen(' http://ctabustracker.com/bustime/map/getBusesForRoute.jsp?route=22') data = u.read() f = open('rt22.xml', 'wb') f.write(data) f.close() f = open('rt22.xml', 'rb') transit_info = str(f.read(), encoding='utf-8') >>> transit_info ('\r\n' '\r\n' '\r\n' ... bunch of stuff ... '\t\t\t222\t\r\n' '\t\t\r\n' '\r\n' '\r\n' '\r\n' '\t\r\n') -- Jim If you only had one hour left to live, would you spend it on Facebook, Twitter, or Google Plus? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] REPL format
On 25 April 2015 at 17:43, Alan Gauld wrote: > know what's going on. I seem to recall you are using Python 3, > is that correct? > > I guess I should specify from now on py3 on win xp Another question - why does the first assignment work but not the second. I can see it's a syntax error but if Py can unpack in the first case why can't it unpack the same thing in the second? >>> a, *b = 'good', 'bad', 'ugly' >>> a 'good' >>> b ['bad', 'ugly'] >>> a, *b = 'ham', 'eggs', 'spam' >>> a 'ham' >>> b ['eggs', 'spam'] >>> *b = 'eggs', 'spam' SyntaxError: starred assignment target must be in a list or tuple >>> -- Jim If you only had one hour left to live, would you spend it on Facebook, Twitter, or Google Plus? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Please disable “digest mode” before participating (was: Tutor Digest, Vol 134, Issue 86)
On 25 April 2015 at 18:03, Ben Finney wrote: > Digest mode should only ever be used if you know for certain you will > never be responding to any message. > That brings up a great shortcut if you use gmail. If you select some text before reply that's All that is sent. Cuts way down on huge reply chains, and saves mooching through your reply to delete all the garbola. However, it has to be enabled in google labs: http://blog.jgc.org/2013/01/the-greatest-google-mail-feature-you.html I just used it to quote only the three lines above (if I got it right ;') It could be some other mail services have this, too. You'd have to look. -- Jim If you only had one hour left to live, would you spend it on Facebook, Twitter, or Google Plus? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] oops - resending as plain text
I accidentally sent as HTML so this is a resend in case that choked the mailing prog ;') I was doing a simple training prog to figure monetary change, and wanted to avoid computer inaccuracy by using only two-decimal input and not using division or mod where it would cause error. Yet, on a simple subtraction I got a decimal error instead of a two decimal result, as per below. What gives? cost = float(input('How much did the item cost?: ')) paid = float(input('How much did the customer give you?: ')) change = paid - cost #using 22.89 as cost and 248.76 as paid twenties = int(change / 20) if twenties != 0: twentiesAmount = 20 * twenties change = change - twentiesAmount #change is 5.8745, not 5.87 - how did I get this decimal error when simply subtracting an integer from what should be a #two-decimal amount? print(twenties, ' twenties') print(change) #and so forth for the rest of the prog Jim Mooney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] How did this decimal error pop up?
I was doing a simple training prog to figure change, and wanted to avoid computer inaccuracy by using only two-decimal input and not using division or mod where it would cause error. Yet, on a simple subtraction I got a decimal error instead of a two decimal result, as per below. What gives? cost = float(input('How much did the item cost?: ')) paid = float(input('How much did the customer give you?: ')) change = paid - cost *#using 22.89 as cost and 248.76 as paid* twenties = int(change / 20) if twenties != 0: twentiesAmount = 20 * twenties change = change - twentiesAmount *#change is 5.8745, not 5.87 - how did I get this decimal error when simply subtracting an integer from what should be a #two-decimal amount? * print(twenties, ' twenties') print(change) #and so forth for the rest of the change -- *Jim Mooney If you shoot a child you're a bad guy. If you splatter forty children across a wall with a bomb, you're a heroic, manly Top Gun with gleaming Tom Cruise teeth. The moral is you'll get laid more if you snuff a lot of children than if you only snuff a few.* ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 110, Issue 69
> Now that Joel Goldstick has pointed out the reason, you may wonder what to do > now. Answer? Use the decimal module: > > http://docs.python.org/2/library/decimal.html > > Although, you might prefer Doug Hellmann's introduction: > > http://pymotw.com/2/decimal/ Thanks. I was about to ask that but you beat me to it. I'll try Hellmann. The manual is just a tad wordy and it's hard to find what you want. Jim > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] oops - resending as plain text
Further question. If I round the input right at the beginning, round(paid,2) does that mean I still have the original error from using .76 even before math, or does the rounding kill it? I would guess not if it's binary, although Python must have a way to handle money amounts. I'm only on Chapter 2 ;') I assume Python has some automatic way to filter input, so that if someone entered three decimals instead of two for a money amount, they could get a wrist slap. Can you direct me to that functionality? Thanks. Jim On 16 April 2013 11:55, Sander Sweers wrote: > On 04/16/2013 07:48 PM, Jim Mooney wrote: >> I accidentally sent as HTML so this is a resend in case that choked >> the mailing prog ;') >> >> I was doing a simple training prog to figure monetary change, and >> wanted to avoid computer inaccuracy by using only two-decimal input >> and not using division or mod where it would cause error. Yet, on a >> simple subtraction I got a decimal error instead of a two decimal >> result, as per below. What gives? > > Floats can not be represented accurately in binary and will have small > rounding errors. See > https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems. > >> cost = float(input('How much did the item cost?: ')) >> paid = float(input('How much did the customer give you?: ')) >> change = paid - cost >> >> #using 22.89 as cost and 248.76 as paid >> >> twenties = int(change / 20) >> if twenties != 0: >> twentiesAmount = 20 * twenties >> change = change - twentiesAmount >> #change is 5.8745, not 5.87 - how did I get this decimal >> error when simply subtracting an integer from what should be a >> #two-decimal amount? >> print(twenties, ' twenties') >> print(change) >> >> #and so forth for the rest of the prog > > You can use string formatting to show as much precision you want. Example: > >>>> n = 5.87000045 >>>> print '%.2f' % n > 5.87 >>>> print '%.4f' % n > 5.8700 > > Or use round(), example: > >>>> round(n,2) > 5.87 > > In your case I would just use string formatting to hide the rounding error. > > Greets > ~sander -- Jim Mooney If you shoot a child you're a bad guy. If you splatter forty children across a wall with a bomb, you're a heroic, manly Top Gun with gleaming Tom Cruise teeth. The moral is you'll get laid more if you snuff a lot of children than if you only snuff a few. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] regex to promote Py 2 to Py 3?
I already tried an example I copied from something online, in Py 2, that had a ton of print statements. So I did some fast search and replace to make them Py 3 with (), since I'm using Py 3. (Except Wing 101 won't do Replace All for some reason I haven't figured out, so it's a bit tedious) So for online progs, examples, ebooks, etc, that still have Py 2 examples I can copy, has anyone come up with a nice regex package to do most of the conversions and produce a mostly Py3 from a Py2? That might make some things a bit easier. I use Clipmate, which has a regex option so I could just copy a Py2 script, run the regex, and paste back a Py3. I could probably work one out but since I don't know Py yet, that could be problematic ;') Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] regex to promote Py 2 to Py 3?
> Generally the 2to3 script does an OK job. If you're using Windows it's > [Python_Dir]\Tools\Scripts\2to3.py. > > http://docs.python.org/3/library/2to3 Thanks. I didn't know where to find it and thought I had to install it. I opened a command window in my Python33/progs dir, started Python, and ran it on a tiny test program called loops.py but I get "invalid syntax" Any idea why?: >>> 2to3 loops.py File "", line 1 2to3 loops.py ^ SyntaxError: invalid syntax The loops.py program simply had the old-style print as a single test statement. ie: print 'Machiavelli' Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 110, Issue 74
> The script 2to3.py is run from the system's terminal/console shell > (e.g. cmd or PowerShell on Windows), not the python shell. Yay, it worked! A decade of Windows and I'm back to the DOS Command Line ;') Well, it worked the second time.I thought I could do without the -w but nothing happened. Now I'll go edit Path so I'm not typing in all those directories. 2to3 doesn't seem to do anything without the -w, which I find a tad puzzling. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] path directory backslash ending
Minor question. I was adding the Py Script directory to the Win 7 Path, and noticed that Python33 ends with a backslash but many directories do not. Is there a difference? Should I use backslash or not preferentially, or doesn't it matter at all? It does seem odd that there's no convention for this. -- Jim Mooney Today is the day that would have been tomorrow if yesterday was today ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] path directory backslash ending
Well, under the principle of least harm, it appears that since the trailing backslash causes no harm if omitted, but sometimes does if allowed, I removed them all. But that's in win 7. Is it okay to always omit them in Linux? Python33 is itself installed with a trailing backslash, so I figured this was a Linux habit. An entirely different question as long as I'm here. I have a local wamp server with mysql and phpadmin for php so I can test web pages locally. What's the equivalent for Python? Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] 3to2?
I was looking at google pengine for python and it only supports 2.7. I've installed 3 and would rather not go back (I kept doing Print without the parentheses for awhile and it was really annoying ;') So the question comes up. If there is a 2to3 script, which I got working, is there a 3to2 script?. Or does that even makes sense since 3 has features 2 does not, although I read somewhere that many have been backported? -- *Jim Mooney Today is the day that would have been tomorrow if yesterday was today * ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 3to2?
On 20 April 2013 12:50, eryksun wrote: > On Sat, Apr 20, 2013 at 2:32 PM, Jim Mooney > wrote: > > I was looking at google pengine for python and it only supports 2.7. I've > > installed 3 and would rather not go back > > Do you mean Google App Engine (GAE)? > -- Yeah, looks like my fingers got tangled. New keyboard. I'm not used to flat buttons. I picked Python to learn since I'm retired and it seemed like the most fun (although I won't turn down a Python contract now and then if I ever learn it well ;'). I tried Ruby and Python and liked the Py indentations so I chose that. But to me, it really is so much more enjoyable to learn it for fun than I've-got-to-learn-this-to-make-money. That doesn't mean I wan to just dabble, though. This is the first language I want to learn formally and in detail, not just to get it over with so I can hack a website. But still, past a certain point, since I was a webmaster, I would of course want to make web-use of it, if only for a nonprofit site, since I've run a few of those. *Jim Mooney Today is the day that would have been tomorrow if yesterday was today * ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Time frame for Py 3 Maturity
> This is why we tend to recommend 2.7 for anyone doing serious work in > Python. > Understood. I am in no rush, but what do you think it the time frame when Py 3 will be mature? A year from now? Two years? At some point I might want to use it more practically. Or maybe there will be huge inflation, I'll go broke, and have to use it more practically ;') Also, is there a good syllabus for the best way to progress in this language? One can certainly get sidetracked. -- *Jim Mooney Today is the day that would have been tomorrow if yesterday was today * ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Py 3 package maturity - good links
> On the other hand, from the perspective of "When will the *majority* of > publicly-available libraries and packages support Python 3, then the answer > is "Right now". The Python 3 Wall of Shame turned mostly green some time > ago, > and is now known as the Python 3 Wall of Superpowers: > > https://python3wos.appspot.com/ > > Based on the number of downloads, almost three quarters of the Top 50 > Python > packages support Python 3: > > http://py3ksupport.appspot.com/ > Thanks. Very useful links to save that would have taken time for me to find on my own. As for "syllabus," probably a dream for a dynamic language ;') I was thinking of the time my brother, a Lit grad, gave me a syllabus of literature to read - still working on it forty years later. Jim * * ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] is there an explicit eof to test in Py 3?
I'm reading a book that suggests finding EOF when the readLine == "" But wouldn't that end erroneously on blank lines, that really contain '\n', in which case more lines might follow? What 'empties' are considered equal in Python? I'm coming from javascript which has a cluster of rules for that. Yes, I know the easy way is a for loop, which automatically breaks on eof, but at times I want to use a while loop and break out of it explicitly on eof. But I can't seem to find an explicit eof marker in python. Is there one? -- Jim Mooney Today is the day that would have been tomorrow if yesterday was today ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] multiple versions of python on windows?
My plan for starting on Py 3 may need some adjustment. I doiwnloaded an irc client that needs Py 2.6 and I think Plone wants 2.7. Is it possible to install multiple versions of python on the same machine or will windows choke? -- Jim Mooney Today is the day that would have been tomorrow if yesterday was today ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] multiple versions of python on windows?
On 21 April 2013 22:47, School wrote: > You can install multiple versions. The programs use the version they were > assigned to, so there shouldn't be any conflict. This brings up the question of installing multiple versions of Wing 101 IDE. I forget the install but even if I can install in a different directory for Py 2.7, Windows awful Registry might trip me up. I've grown to love portables since they bypass Windows Worst Idea, but Wing isn't one of them. If anyone knows, does the paid version of wing allow to switch between multipe installs? I know, this is probably a Wing discuss question, but I'm burned out on joining discussion groups to ask one question, since otherwise Wing is very easy to grasp. -- Jim Mooney Today is the day that would have been tomorrow if yesterday was today ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Why is my list index going out of range
Okay, what am I doing wrong here? I'm generating primes from a list and getting "list index out of range," but since the for loops controls the indexes I don't see how that's happening. I thought it was the list append, but I commented that out and put in a print statement, and I still got the line 5 error: primeList = [1] numList = list(range(2,101)) for e in numList: for f in primeList: if numList[e] % primeList[f] != 0: #list index out of range primeList.append(numList[e]) print(primeList) -- Jim Mooney The Real Reason Things Keep Going Wrong: At the beginning of time, God set a Magic Top Spinning... and spinning... and spinning... and spinning... and spinning... and spinning... and spinning... After a few hundred million years God got bored and gave the top a good kick; so it went rebounding away, flinging off planets and stars and dinosaurs, and later, people who wrote about dinosaurs. Then God realized that although Order and Regularity are virtuous, if you want interesting stories, now and then you have to give things a good Kick! This explains a lot. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] changing list element in loop
Why isn't 'e' changing to 'pP here when the vowel list is mutable: vowelList = list('aeiouy') for x in vowelList: if x == 'e': x = 'P' print(vowelList) #result: ['a', 'e', 'i', 'o', 'u', 'y'] -- Jim Mooney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] changing list element in loop
On 27 April 2013 02:55, Amit Saha wrote: > On Sat, Apr 27, 2013 at 7:49 PM, Jim Mooney wrote: >> Why isn't 'e' changing to 'pP here when the vowel list is mutable: >> >> vowelList = list('aeiouy') >> >> for x in vowelList: >> if x == 'e': >> x = 'P' > > This is because x is really a label for the item in your list. It does > not represent a reference to the position of element as it occurs in > the list. For example: Okay, I tried enumerate, but now I get an "immutable" error. So let's turn this around since it's getting out of hand for a simple list replacement ;') What's the simplest way to go through a list, find something, and replace it with something else? vowels = 'aeiouy' vlist = enumerate(vowels) for x in vlist: if x[1] == 'e': x[0] = 'P' print(vowels) #'tuple' object does not support item assignment ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Why isn't iteritems() working when items() does?
#Changing a dictionary into a 2-tuple list with the items method works, as per the #first example. But using iteritems returns an error - using Py33 dick = {'villain': 'Roderigo', 'hero': 'Othello', 'friend': 'Cassio', 'beauty':'Desdemona'} dickList = dick.items() for role, name in dickList: print(role, name) #The above works, but using iteritems() in place of items doesn't dickList2 = dick.iteritems() for role, name in dickList2: print(role, name) #error: builtins.AttributeError: 'dict' object has no attribute 'iteritems' -- Jim Mooney Texting a program as he drove, John inadvertently dereferenced a null pointer, and a huge crash ensued. The good thing about crocodile farts is few of us feel the need to get that close to a crocodile. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 110, Issue 117
> In py3.x, iteritems was replaced by .items() Interesting, since iteritems was in my book, which was "updated" for Py33. I guess the moral is you shouldn't trust an author 100% ;') I must admit, iteritems did seem awkward and annoying so I'm glad it's dropped. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] changing char list to int list isn't working
I'm turning an integer into a string so I can make a list of separate chars, then turn those chars back into individual ints, but the resulting list still looks like string chars when I print it. What am I doing wrong? listOfNumChars = list(str(intNum)) for num in listOfNumChars: num = int(num) print(listOfNumChars) # result of 455 entered is ['4', '5', '5'] -- Jim Mooney “For anything that matters, the timing is never quite right, the resources are always a little short, and the people who affect the outcome are always ambivalent.” ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] stumped by what looks like recursive list comprehension
I looked up "list comprehension" after the last explanation and it's really cool. But the example below stumps me. I understand the second part, "primes =" but the first part, "noprimes =" baffles me since it swaps i and j back and forth in what looks like a circle ;') Also, the other examples I looked at had a function of 'x' before the 'for,' and 'x' after, so they were easy to follow. But this example has 'j' as a function of 'i,' then 'i,' as a function of 'j' and has me dizzy. Could someone show this in normal, indented 'for' loops so I can see what 'for' goes where and how it works. I figure if I figure this one one I'll really comprehend list comprehension. # find nonprimes up to 50, then filter out what's left as primes noprimes = [j for i in range(2, 8) for j in range(i*2, 50, i)] primes = [x for x in range(2, 50) if x not in noprimes] -- Jim Mooney “For anything that matters, the timing is never quite right, the resources are always a little short, and the people who affect the outcome are always ambivalent.” ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] exit message
I've noticed that if you exit() a program you always get a traceback message: Traceback (most recent call last): File "", line 1, in exit('what now?') File "C:\Python33\lib\site.py", line 380, in __call__ raise SystemExit(code) What if you just want to exit for some normal reason and don't want the message? Or is a program always supposed to end in some normal way without an exit. Or is there a different, more graceful way to end a program when you want? -- Jim Mooney “For anything that matters, the timing is never quite right, the resources are always a little short, and the people who affect the outcome are always ambivalent.” ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] exit message
> Something like this? > >>> import sys while 1: > ... sys.exit('Exiting from Infinite Loop') > ... > Exiting from Infinite Loop I still get a traceback message from the console. I just want a clean exit without that. I have a feeling I'm thinking about something the wrong way ;') Traceback (most recent call last): File "c:\Python33\Progs\fileActions.py", line 17, in builtins.SystemExit: you messed up too many times Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 111, Issue 11
> I believe that traceback is a bug in IDLE, which I think has been > fixed for the next release (or is being chased, one of the two). Ah, that clears it up. I've been using IDLE and Wing. Both have the traceback so I guess Wing uses some IDLE code. But I tried it in the command shell, which I haven't used in a while, and no traceback. So that's solved. A production program wouldn't be using the IDLE interpreter or Wing editor so there won't be a traceback littering the screen. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] PyScripter header?
I'm trying PyScripter instead of Wing 101. It works fine and has a lot more PyLearner features than Wing 101 (at the same price ;'), such as popups showing the parameters for methods, profiler, lint, programmable snippets, etc. It also lets you choose your Python version and finds the right one, which is handy, since I'm learning on 3.3 but a lot of good stuff is older. However, a new file in PyScripter always starts with: _ def main(): pass if __name__ == '__main__': main() _ What is that stuff? I thought I was getting away from all this business of defining a main entry point. I don't see it in any of the Py library files or other Py programs. PyScripter has enough extra features, that I'll probably switch to it. But has anyone found any odd problems with it? Tks. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 111, Issue 19
> Given that your main() question ;c) has been answered, you might also > want to give Spyder a try before switching. Thanks - I'll try that if it's not overkill for a basic learning tool, or has a ton of dependencies I have to install, or isn't up to Py3.3. PyScripter had an odd bug. Whenever I started a parentheses or dot, for a function or method, it would autocomplete the paren, then pop up a type error warning. On dots it popped up every other letter I typed. Quite annoying, so I've turned it off until I see if there's a tweak to fix that or I'm just doing something stupid (which is always possible ;') Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] bad name in module
I have a simple program, below, to create a specified list of random integers, which works fine. I saved it to Lib as makeRandomList.py, then imported it to a sorter.py program, like so. The import doesn't fail: import makeRandomList newRandomList = createRandomList() But I then get the following error: File "c:\Python33\Progs\sorter.py", line 3, in builtins.NameError: name 'createRandomList' is not defined What am I doing wrong in creating the library module below, which works fine as a standalone? program saved to Lib directory as makeRandomList.py import random random.seed() def createRandomList(): while True: listLength = input("How big a list do ya want, Corky? ") try: listLength = int(listLength) break except: print("That's not an integer, Corky - try again: ") while True: maxNumberSize = input("How big should the biggest number in the list be? ") try: maxNumberSize = int(maxNumberSize) break except: print("That's not an integer, Corky - try again: ") randomList = [] for c in range(0,listLength): randNum = random.randint(0,maxNumberSize) randomList.append(randNum) return randomList -- Jim Mooney “For anything that matters, the timing is never quite right, the resources are always a little short, and the people who affect the outcome are always ambivalent.” ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 111, Issue 24
> As with any other module you need to specify the module when using its > contents: > > newRandomList = makeRandomList.createRandomList() > > BTW. A better name for the module is probably just randomlist > > HTH > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ Ah, me so stupid. That workede. Although I recall making a very simple test program that didn't use the module prefix and it worked for some odd reason. I just made a dummy prog that said print('thisworks'), put it in Lib, imported with a test prog, and it printed out. Which is why I got confused. Oh well, I'll just ignore that and use the prefix. BTW, does your "better name" mean that camelCaps are discouraged in Python? I loathe finding the underline key and figured it was a good way to always avoid Python reserved words. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 111, Issue 24
>> BTW, does your "better name" mean that camelCaps are discouraged in >> Python? > > No, although most Python modules are all lowercase. But I really meant that > your module should be for more than just making lists, it should eventually > have all the functions needed to manage the list. > > Eventually maybe even a class to encapsulate those functions > as methods. Good point. But I'm just making a test list for now to feed into a sort program, so I'll gussy it up later. I'm not using sort(), so I can get the practice of raw-coding sorts. Since getting indexes is roundabout in a Py for-loop, I'll have to think about the best algorithm ;') As regards camelCaps, all I see in the Py Lib is underlines, so I guess that's more of a convention and I might as well stick to it, since some programs might become modules. I don't want to spend forever deciding what style to use, when I could be programming. I see there is a proposed manual of style at http://www.python.org/dev/peps/pep-0008/ so I'll look at that. I think both camelCaps and underlines are often artifacts having to use short names years ago. A plain language phrase that isn't hard to spell or almost purposely confusing (like repeated letters on a word boundary) should do most times without camelCaps or underlines, unless you really need them for clarity, so I'll go with underlines, but only when needed for clarity. And of course, a plain, descriptive name makes a program almost self-documenting, so you save on hashmarks. I'm using Windows, which doesn't recognize case difference, so camel caps for a program name are confusing, anyway. I never figured why Msoft did that. Even in normal English, cASe is enfOrcEd for good reason. By trying to make it simpler, Msoft made it harder (Not the first time that's been done ;') Since this is a beginner list, I think bringing up Python Preferred Style is reasonably on topic. I'm a retired webmaster, so readability and idiot-proofing are a BIG item with me. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] range efficiency
If I'm using a variable-dependent range in a for loop, is Python smart enough to figure the variable once so I don't have to hoist it up? That is for c in range(0,x+2), is x+2 figured once or every time through the loop? I'm assuming it's once but I like to verify. I'll figure this myself once I get an editor I like with a profiler, but I'm still trying editors and don't want to spend all my time on them. So far I'm in between too simple, overkill, or buggy. And I don't want anything that uses Java. I'm allergic to Java ;') -- Jim Mooney “For anything that matters, the timing is never quite right, the resources are always a little short, and the people who affect the outcome are always ambivalent.” ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] variable in format string throwing error
I'm trying variable substitution in a format string that looks like one that works, but I get an error. What am I doing wrong? tks x = 40 s = 'John flew to the {0:-^{x}} yesterday' print(s.format('moon', x)) Error is builtins.KeyError: 'x' -- Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Bugs came home
Just a note about PyScripter since I was whining here about some bugs, but the bugs were mine ;') I downloaded Py 64-bit for Py 3.3 but for some reason installed 32 bit for Py 2.7. PyScripter runs multiple Pys but it apparently choked on the different word lengths. Once I installed 64 bit for both Pys, the bugs died. Now I can run Py 2.7 from the Taskbar, since all the graphics modules and a lot of other kewl stuff are still mostly for 2.7, but continue to explore 3.3 from the Start Menu. PyScripter does have some nice stuff - multiple Pys, Projects, Debugger, Regex search, templates, startup scripts, and other useful tools not in Wing unless you buy the paid version. But it's easy to use out of the box if you don't want to mess with that stuff right off. And its folder has a start link for each installed Py, so you don't have to set anything up except the path to each Py. So my bad on the reported PyScripter bugs ;') -- Jim Mooney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Pygraphics crashed
How do I uninstall modules? I installed Pygraphics, which worked fine, along with some other mods, like numpy, but when I installed 64 bit py 2.7 I get the message "The _imaging C module is not installed" when running a prog that worked fine before. I think I have a higher dot-version - Py 2.7.4 as opposed to 2.7.3 - what's the easiest way to fix this? Will uninstalling and reinstalling the modules do anything or do I have to revert to an older Py (I'm on Win 7) And regardless of the answer to that I still want to know how to uninstall modules. Do I just find and delete them? And are they all in the same place? -- Jim Mooney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Can't install latest PIL
Okay, I'm trying to install the latest PIL on win 7. It claims Python 2.7 was not found in the registry, although it's installed, on a path, and works fine. The install box lets you type in a directory but won't accept typing. I'm stumped. I guess the way around this is to know what I have to put in the registry. -- Jim Mooney “For anything that matters, the timing is never quite right, the resources are always a little short, and the people who affect the outcome are always ambivalent.” ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Can't install latest PIL
Make sure you have the correct architecture. The builds from PythonWare are 32-bit. Christoph Gohlke has 64-bit builds here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil == Okay, I installed the 64 bit for Py 2.7, it installed, I see PIL directory in Site-Packages. (Actually, it's the Pillow fork, but it still seems to be named PIL) I tried "import image from pil" and got the following error: SyntaxError invalid syntax (python_init.py, line 1) I don't see where that prog is, so it's an install somewhere and I don't want to mess with it anyway. Oh well, be nice to get back to learning Python after wrestling with editors, installs, and Windows ;') Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Pygraphics crashed
How do I install PIL with easy-install? I used that once but forget how. I seem to recall reading it installs a version that is Py native and doesn't choke on your OS. Or did I read that wrong? Jim On 16 May 2013 02:44, eryksun wrote: > On Thu, May 16, 2013 at 2:06 AM, Jim Mooney wrote: >> >> And regardless of the answer to that I still want to know how to >> uninstall modules. Do I just find and delete them? And are they all in >> the same place? > > You should be able to uninstall msi or exe packages just like any > other Windows program. pip has an uninstall command if you used it to > install a package. If you used easy_install, you'll have to manually > delete associated eggs and egg-info directories from > Lib\site-packages, defunct scripts in Scripts, and also edit > Lib\site-packages\easy-install.pth to remove deleted cruft. It's > definitely not easy_uninstall. -- Jim Mooney “For anything that matters, the timing is never quite right, the resources are always a little short, and the people who affect the outcome are always ambivalent.” ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Pygraphics crashed
> By the way, do you mind if I ask why you're using PyGraphics? It's > only meant to be used for education (and even there, AFAIK the only > users are the University of Toronto (and even there, I think they > stopped using it because they switched to Python 3 for Coursera and > didn't care enough to upgrade PyGraphics (I am mad about this))). > Yeah, I'm tired of fighting 64 bit windows. I'm going to uninstall everything and use 32 bit I was reading some advice to use 64 bit for speed but I'm only learning - I don't need to keep wrestling with this crap just get top speed for twenty line programs ;') PyGraphics was an import in a program right at the front of a book I'm using. Worked fine for displaying jpgs very easily, before I started fooling with 64 bit. Let me see, the book is called: Practical Progamming - an introduction to computer science using Python by Jennifer Campbell, et al. It's not my main book - it's just for doing something more active while I slug through Guttag's MIT open courseware on Python. Guttag covers all the bases, but in the meantime I want to see pretty pictures and see what Python can do ;') Right now I'm using both Py 2.7 and Py 3.3 since I want to learn 3.3 but half the good libs are still in 2.7. Actually, neither the book or Guttag is pure Python, but just using Python to teach computer science. I'm a retired webmaster and hacked away just enough at javascript, jquery, and php to get something done on a site, but I figured I'd actually learn this from the ground up now that I have time and don't have to be hustling a site all the time, and just grab some jquery and get it done. I may have to look at a dedicated Python book for detail, since the book and course I have admit they just scant Python to get on with computer science. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Can't install latest PIL
On 16 May 2013 16:11, James Reynolds wrote: > You may want to consider pillow. Oil hasn't been maintained in some time. Actually, I installed Pillow. But then I deleted everything and started over with 32 bit. I got greedy figuring I'd get the fastest Py with 64 bit, but there are too many kludges involved and I'm tired of it so heave-ho on all the 64 bit. Back to 32 bit. All modules and showing pretty pictures with Py work again. It doesn't pay to be greedy (except with regular expressions, of course) Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Can't install latest PIL
> If you see a syntax error, that means your code could not be compiled. > Python's parser doesn't grok "import image from pil". In natural > language we have the freedom to swap the order of clauses, but > programming languages are generally more rigid. The correct order is > "from pil import image" -- but actually it has to be "from PIL import > Image". Yeah, I fixed that but it still blew a fuse. Going back to 32 bit fixed everything. from ** import ** just sounds backward to me, so I'll get it wrong until I get it right. Actually, it is backward by standard English - a design flub ;') BTW, I noticed that Msoft Visual Studio has Python. Does that mean I could made a standalone Win executable with Python, or would a user still need the Py interpreter installed? It would be nice if you could make an exe. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] WAMP stack
I noticed someone mentioned WAMP stacks but didn't see the answer. I use a WAMP stack a lot. It has PHP. But I used it mainly with PHP CMS. How do I install Python into my WAMP stack, and does that make any sense for just raw Python, or only if I want to load Django or something web-oriented and test it? (Assume I know nothing about Django other than it's a Py CMS, since I don't ;') Jim Mooney "Since True * True * True == True, what I tell you three times is true." --The Hunting of the Snark ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] creating import directories
I'm a bit unclear about creating import directories. I can import something like the json directory from Lib with a simple import json So I tried putting my own directory in Lib, called bagofries, as a test, and put a simple printstuff.py program in it. But when I try to import bagofries, I get "no module named bagofries" Is there some reason I can put a program right under Lib and it imports, which it does but not a directory? Also, I noticed Wing 101 is sometimes creating a same-named pyc program alongside my py program, but I don't see an option to do that. -- Jim Mooney Today is the day that would have been tomorrow if yesterday was today. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 111, Issue 61
> 1) The directory must be somewhere that Python will see it, no different from > a single file module. That means, in the current directory, or your > PYTHONPATH. Since Python on Win 7 can already find modules in Lib (and in site-packages, under Lib) can I assume that it will find any directories fabricated as mentioned, that are put in Lib or one of its subdirectories, without doing anything further? Also, I didn't have a PYTHONPATH so I made one, but are you allowed multiple directory entries separated by a semicolon, as in the plain Windows Path? And just how detailed must PYTHONPATH be? Can it just be the PYTHON27 and PYTHON33 directories, or does it have to drill down to Lib or directories beneath that? Since there was no PYTHONPATH I figured the win path was enough, but I put one in anyway. Or does Win 7 put something in the registry? (I'm not sure which I dislike more - IE or the Registry ;') Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] from import works but I'm flubbing a package import
Still puzzling on imports. I have the jimlib module in Lib with the proper __init__.py . Inside it is the program bark.py, with data item zarf that contains string 'fraz' It also contains the function barker. def barker(): print 'bark, bark' If I do the below everything works: from jimlib import bark print bark.zarf bark.barker() But if I just do import jimlib and chain the program and its functions or data nothing works. If I try jimlib.bark.barker() after importing jimlib or print jimlib.bark.zarf I get the error that the module has no attribute 'bark' I'm doing the from statement right but what am I doing wrong with just importing the whole module and chaining out bark (for bark.py) and the function or data following? Using Py27 and Win 7 -- Jim Mooney There is no such thing as a failed experiment ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 111, Issue 68
> > import random > > > > Count = 0 > > > > Random_Number = random.randint(1, 100) > > > > while Count <= 100: > > print (Random_Number) > > > > Count = Count + 1 > > There are a few issues here: > * variable names should be lower case > * for this case it's best to use for loop with range() > * you calculate random number only once, outside of loop This gave rise to an interesting behavior, though. I ran it with random outside the loop and indeed got the same number. Except the number Changed right toward the end to one other number. I got a lot of 19s, then a 17. The third time I got a lot of 23s, then a lot of 70s. This was consistent. Then I scrolled the results more slowly and realized the program ran over 25,000 times and the anomalous numbers were toward the end. So why did it run about 25,000 times and why the change in number? Here's the prog so you can see the loopvar count does increment so it Should stop at 100. import random Count = 0 Random_Number = random.randint(1, 100) Count = 0 while Count <= 100: print (Random_Number) Count = Count + 1 I found the cause. If I just print Count it only goes to 100. If I print Random_Number it goes to 25K. Is this consistent or a strange flaw of Pyscripter? Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] still clarifying imorting
If I make a package called jimlib with __init__.py in it, and a program called bark.py in it, and even put it in site packages, I still have to import the program with import jimlib.bark But I noticed that the pygraphics package is in site packages, and has media.py in it, and all I have to do with that is import media, without qualifying it with pygraphics, as in import pygraphics.media Why don't I have to drill down for media.py as I do with jimlib? -- Jim Mooney "And as he walked along he carried some things in his small sack. Some were useless and some were not. But the useless things he prized most of all." --The Story of Dirtville ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] nose error
I'm trying a nose test on a simple prog. Once I got past the huge traceback in Wing that made me think nose didn't work I realized the prog tested okay. But I noticed at the end of the traceback nose says this: "c:\Python27\Lib\site-packages\nose-1.3.0-py2.7.egg\nose\core.py", line 200, in runTests sys.exit(not self.success) SystemExit: False As i said, nose works and says Okay on the asserts (or not if I give things a bad value). I was just wondering what they SystemExit: False meant, or is that standard? Jim "When I got to high school I realized my name would always present problems." --Dick Hertz ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] still nosing around
Okay, why is nose saying this run is OK when I purposely screwed it up? import nose def stand_and_deliver(): return 52 def stupid_error(): '''This is my stupid error''' assert stand_and_deliver() == 17 if __name__ == '__main__': nose.runmodule() nose result: Ran 0 tests in 0.000s OK -- Jim Mooney "When I got to high school I realized my name would always present problems." --Dick Hertz ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 111, Issue 72
> Do you ever bother to investigate anything before posing a question? Actually, I did notice that tests were zero, but the book I am using does not mention needing the word 'test' as part of the regex. There is only so much time in a day and so many books I can buy (and not all comprehensive, apparently.) That is why this list is an excellent ancillary to save me time. Otherwise, learning Py will take me a lot more time than I can budget. I'm not reading all the docs right now - which I used to and may in the future - because I'm trying a different method of just running a lot of progs to get up to speed. I figure once I "grok" the language, docs will be a lot easier. There is a certain logic to every language so you can anticipate what is right, but I'm not there yet. But that brings up a point. Does this mean that if I have to test a module with a lot of subroutines I have to rename every subroutine with 'test' appended? Try replying with a bit less emotion ;') Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] try..except - what about that ton of **Error statements?
I'm looking at Try..Except Try: Except SomethingError as err: The list of error statements is huge. How do I know which error statement to put in place of SomethingError (or multiple errors for that matter)? Or is it best to just leave SomethingError blank until I know more? ( I have an asymptotic learning curve, so I go off on a lot of confused tangents, but I find it makes things go a lot faster after a certain point.) -- Jim Mooney "When I got to high school I realized my name would always present problems." --Dick Hertz ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] try..except - what about that ton of **Error statements?
> Keep the try block small. For example if it's for a call to > open(filename, "r") the only possible errors (assuming correct syntax) > are NameError for using an undefined variable and IOError for > specifying a file which doesnt exist. Thanks. Since I'm new at this the error lists I saw just had the bald names, which didn't tell me much. But I found a concise and basic explanation of each error at http://python.about.com/od/pythonstandardlibrary/a/lib_exceptions.htm Although it's still a bit circular at my level. I won't be sure what errors to raise until I see enough errors, but that will come with experience, I guess. Now I just have to figure how to print the list out without the ads ;') Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 111, Issue 72
> Please don't reply to digests. Each message has a Message-ID, and > replies have an IN-REPLY-TO field that references the ID of the > previous message in the thread. By replying to the digest your message > has no meaningful Subject, and even if you change the Subject field, > it still won't be threaded properly. See for yourself: > > http://mail.python.org/pipermail/tutor/2013-May/thread.html#95572 So is Reply to All the way to go? For some odd reason Gmail won't always Reply to All. I'll have to figure out why. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] To error statement or not to error statement
>> "I find it amusing when novice programmers believe their main job is >> preventing programs from crashing. ... More experienced programmers realize >> that correct code is great, code that crashes could use improvement, but >> incorrect code that doesn't crash is a horrible nightmare." Then am I right to assume that rather than put in error statements I barely understand at this point, the best thing would be to work the hell out of the program in hope of seeing an error? Does Python have something that would do this automatically since I can't see running a program a hundred times by hand? Mainly, I'm just learning all this stuff for future reference. I really doubt I'll need to use nose to find errors in twenty-line programs. Print, assert, and staring at it for a long time should be enough for now - and the Wing debugger now and then. >From the varied replies so far, it sounds to me that debugging is more of an art than a science. So far the books I've looked at just mention the basics but don't get into the philosophy of when and how. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: Available characters
> The unicodedata module provides access to the Unicode database that Python > uses: > > http://docs.python.org/2/library/unicodedata#unicodedata.unidata_version That was really useful for another reason. After I checked and saw it was in DLLs, I investigated the other Python DLLs - which had heretofore seemed mysterious - and found winsound. I happen to be interested in frequency generation. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] keyboard interrupt
I made a simple ear frequency-tester, but I don't want it to go on forever, so I tried stopping it when I pressed a key, as below, but that doesn't work. I did check out keyboard interrupts but they seem unnecessarily complex just to stop a program. I'm not passing keys. Is there something simple I'm missing? import winsound try: for freq in range(100,32000,100): winsound.Beep(freq, 1000) except KeyboardInterrupt: pass -- Jim Mooney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] keyboard interrupt
> I've not used it myself, but I believe the KeyboadInterrupt is only > generated by one _specific_ keypress. You mentioned that you pressed a key > - did you try Control-C? Actually, I did, using Win 7 - and I put exit() in place of pass. I tried ctrl-c, ctrl-x, esc, and del. Windows doesn't seem to respond to anything. The prog just goes to the end Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] keyboard interrupt
On 22 May 2013 13:24, Jim Mooney wrote: >> I've not used it myself, but I believe the KeyboadInterrupt is only >> generated by one _specific_ keypress. You mentioned that you pressed a key >> - did you try Control-C? > > Actually, I did, using Win 7 - and I put exit() in place of pass. I > tried ctrl-c, ctrl-x, esc, and del. Windows doesn't seem to respond to > anything. The prog just goes to the end > > Jim Figured it out. Ctrl-C only works in the Windows Command window, not in an editor. Jim -- Jim Mooney "When I got to high school I realized my name would always present problems." --Dick Hertz ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] keyboard interrupt
On 22 May 2013 15:05, eryksun wrote: > On Wed, May 22, 2013 at 4:30 PM, Jim Mooney wrote: >> >> Figured it out. Ctrl-C only works in the Windows Command window, not >> in an editor. > > Which IDE? Wing. But not being able to abort out of a Windows program is a feature. You don't want to lose seven hours of spreadsheet work because you forgot and hit ctrl-C. (I just hit Ctrl-C. Nothing, which is as it should be ;') Well, it's good to be reminded that an editor does funny stuff as opposed to command line. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] keyboard interrupt
> What do you mean "doesn't do anything" ? It certainly terminates the loop, > which was the intent. Provided of course that something else isn't trapping > the Ctrl-C first. It doesn't in Windows proper, using Wing 101. It does exit in the Windows command console. For some reason I forgot ctrl-C is Copy in windows. I tried Ctrl-X but I was again confusing the old DOS abort with Windows Cut. I've been enslaved by the GUI ;') I'm using Wing 101, which doesn't have a feature set for altering that behavior. It's probably in the professional version. If I scrape up spare cash I may go for PyCharm or Wing Pro, but I don't need them on the low end of the learning curve. I'd just waste time fooling with them. The program does exit in Idle, although Idle throws up a Tk screen asking if you want to abort the program, so it's not a clean exit. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] keyboard interrupt
> Apparently Wing isn't as savvy as IDLE when it comes to communicating > with the subprocess. I've only searched for about a minute, but > apparently the way this works in Wing is to "Restart Shell": > > http://stackoverflow.com/a/10360503/205580 > http://www.wingware.com/doc/debug/interactive-python-shell > > This kills the suprocess and starts a new interpreter. Crude, but it > should get the job done. Thanks. I'll put stackoverflow on my bookmarks. There is still a difference, though. The program (as corrected below) prints out the last sound heard as a hearing test, if you press Ctrl-C in Idle or the Windows Command Console, but prints nothing if you use Option > Restart Shell in Wing 101. Here's the corrected program if anyone wants to test their hearing ;') Oh, as a tip for winusers who have avoided the Win command console, I also did because I thought you had to type in one line at a time. I just found I can right-click > paste an entire Py program in (after you start Python). The prog then starts after you hit Enter twice. This is Win 7. import winsound try: for freq in range(100,32000,100): winsound.Beep(freq, 1000) except KeyboardInterrupt: print 'last frequency heard was', freq - 100 exit(0) -- Jim Mooney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] making a random list, then naming it
I keep needing random lists of integers for trying things, so I wrote a small prog I'll import as randlist. The user enters the length and max val, but then I want the actual data name of the random list created, to be list_(length entered)_(max value entered) as an easy mnemonic. I got as far as making the list, but my brain is fozzled on changing the numbers entered into part of a data name. Feels like I have to go outside the program to do it: import random random.seed listparameters = raw_input('\nEnter two numbers, space separated, for the length and largest value of a zero-starting random list, which can be used as variable name: randlist.list_len_max , where len is the list length you entered, and max is the largest value\n') listargs = listparameters.split() rlist = [] length = int(listargs[0]) maxval = int(listargs[1]) for r in range(0,length): rlist.append(random.randint(0,maxval)) listlenmax = 'list' + '_' + str(length) + '_' + str(maxval) # just the name of a string, not the data name I want #just printing the below as a test - they'll be removed when the import works print print rlist print print listlenmax -- Jim Mooney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] making a random list, then naming it
> The short answer is that Python is not designed to be able to do such a > thing. You're advised instead to make a dictionary, where the key is the > name you generate I was probably unclear what I wanted to do. Basically, enter a string of number pairs of lengths and maxvals to create and print multiple lists, and name them, so I could fool around with them and not have to remember each one. I noodled around google and found something to do that. I haven't done the multiple lists or listing those lists, or input filtering yet, but I named one list, tested it as a real int list, and it seems to work. Unless I'm confused ;') import random random.seed listparameters = raw_input('\nEnter two numbers, space separated, for the length and largest value of a zero-starting random list, which can be used as variable name: randlist.list_len_max , where len is the list length you entered, and max is the largest value\n') listargs = listparameters.split() rlist = [] length = int(listargs[0]) maxval = int(listargs[1]) for r in range(0,length): rlist.append(random.randint(0,maxval)) listlenmax = 'list' + '_' + str(length) + '_' + str(maxval) + ' = rlist' exec listlenmax #I entered 20 and 120 just as a test, but any ints will work. The program will be changed to list the data names and lists created, accept more than one number pair so I have multiple lists, and I'll add some input filters, then put it in jimports list_20_120[0] += 10042 # test to see if it's a real int list by adding a large number to element zero print list_20_120 #this is hard coded but I'll make a list of names taken from input, that I can use #result from one run was: [10095, 98, 110, 89, 86, 2, 51, 88, 36, 20, 85, 84, 98, 20, 11, 64, 17, 111, 22, 5] #The first number is bigger than the 120 max so it must work. #the docs on exec were kind of inscrutable. I think some of the docs expect you to know what you're doing before you read them ;') But I found some examples and ran a bunch of monkey-see, monkey-do progs. I haven't really gotten to dictionaries yet, but this seems to work. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] making a random list, then naming it
On 24 May 2013 18:10, Dave Angel wrote: > Is lists[(3,8)] really so much harder to type than > list_3_8 ? > You have a point. I hate underlines - my finger always misses them. Keyboards were not designed for programming ;') Anyway, I just thought I'd try exec, but it's giving me fits putting it in a function so I can do multiple lists. A dictionary looks more manageable. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] why can you swap an immutable tuple?
I thought tuples were immutable but it seems you can swap them, so I'm confused: a,b = 5,8 print a # result 5 a,b = b,a print a # result 8, so they swapped # but if I test the type of a,b I get a tuple testit = a,b print type(testit) #comes out as a tuple print testit, # result is (8,5) # So how am I swapping elements of a tuple when a tuple is immutable? #t rying so change a tuple since I just did it testit[1] = 14 #program crashes - *TypeError: 'tuple' object does not support item assignment *so the tuple I just changed is indeed immutable -- Jim Mooney "Coding? You can get a woman to do that!" he said with a sneer. --heard from a physics professor in 1969 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] why can you swap an immutable tuple?
On 25 May 2013 18:34, David wrote: > On 26/05/2013, Jim Mooney wrote: > > I thought tuples were immutable but it seems you can swap them, so I'm > > confused: > > > > a,b = 5,8 > > I think your confusion might arise from not understanding that the > meaning of the comma differs depending on whether it is on the left or > the right side of an equals sign. > I think the problem is the book I'm reading, which never mentions "unpacking," so I thought from hearing a comma creates a tuple, that it was tuples on both sides ;') I'm reading Learning Computer Science With Python and I think it's scanting the Python-detail to get on with the CompSci. I'll go look for something more PyDetailed ;') -- Jim Mooney "Coding? A woman can do that! he sneered" --heard from a physics professor in 1969 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] why can you swap an immutable tuple?
On 25 May 2013 19:38, Steven D'Aprano wrote: > On 26/05/13 05:23, Mark Lawrence wrote: > > On the right hand side, 5,8 creates a tuple, which is then immediately > unpacked to two individual values. You can see this by disassembling the > code. In 2.7, you get this: > > py> from dis import dis > py> code = compile("a, b = 5, 8", "", "exec") > py> dis(code) > 1 0 LOAD_CONST 3 ((5, 8)) > 3 UNPACK_SEQUENCE 2 > 6 STORE_NAME 0 (a) > 9 STORE_NAME 1 (b) > 12 LOAD_CONST 2 (None) > 15 RETURN_VALUE > > That disassembling looks like it could clarify a number of things. I'll have to try it. It might make more sense to me since my only programming, besides a bit of javascript copy-hacking for websites, was A86 Assembler, some decades ago, when I wrote an ASCII Art prog for Fidonet. Then I got into other fields entirely to make a living. But Asm actually makes sense to me and the disassemble looks close to it. (I can't count the times I wiped out DOS and had to reload it ;') A86 had a wonderful macro language, though. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] got text switched
Oops, Gmail switched me back to rich text. My apologies. Back to plain ;') I wish I could automate the mode, per-recipient, since I do need rich text for some things. The way gmail defaults seems to change from month to month. -- Jim Mooney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] making a string
On 25 May 2013 20:49, Tim Hanson wrote: > A lot of people tend to be intimidated by Mark Lutz, and so am I, I guess. Interesting coincidence. This is a retirement project and I just decided on the Lutz book, which looked comprehensive, since the book I'm using is more CompSci but PyDeficient. However, the 4th edition I of Lutz that I got only goes up to Py 2.6. As a general question - is there any Big difference between 2.6 and 2.7 (the Py version I'm using) that I should look out for so I don't get tripped up? Jim Mooney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] making a string
On 26 May 2013 02:51, Mark Lawrence wrote: > Basically no. Python 2.7 is guaranteed to be backward compatible with > Python 2.6. New or improved functionality will be listed in the "What's New > for Python 2.7". In fact if you look at the "What's New for Python 3.3" > you'll find all of the "What's New" going back to Python 2.0. See this > http://docs.python.org/3/whatsnew/index.html. That's a relief. I started with Py 3.3, realized a lot of stuff wasn't there for it yet, regressed to 2.7, but still write "input" instead of "raw_input" now and then, producing an error I think is mine until I see what I did ;') "raw_input" is such an awkwardness for a very common use, that I'm surprised it was there in the first place. Incidentally, I was figuring how to use compile for multi line statements since the example I saw was a single line, compiled a small multi-line routine nicely, and realized I had just compiled a bad syntax error. I was trying to iterate an integer. Good to know that compile doesn't check syntax, since I erroneously thought it did. -- Jim Mooney There are those who see. Those who see when they are shown. And those who do not see. -- Leonardo da Vinci ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] keyboard interrupt
On 26 May 2013 15:33, Marc Tompkins wrote: > On Sun, May 26, 2013 at 6:17 AM, eryksun wrote: StackOverflow may be good but I just had an unpleasant experience wanting to add New .py file to my Windows context menu. The first advice I saw was missing a backslash and had me adding the string to the wrong key. Thankfully, it didn't work and I figured out what was wrong, so I now have New .py file ;') Bad programming advice is bad enough, but putting up bad advice to edit the Windows registry is Really, Really bad. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] making a string
On 26 May 2013 17:20, Steven D'Aprano wrote: > On 27/05/13 07:40, Jim Mooney wrote: > >> Good to know that compile doesn't check syntax, since I erroneously >> thought it did. > > > compile does check syntax. I'm unclear on something. The code below creates bytecode and I don't see an error message unless I also tack exec code on the end of it. It has the dumb error of trying to iterate an integer. from dis import dis code = compile( '''a, b = 5, 8 print a print b for x in a: print x ''','', 'exec' ) dis(code) Result below - bytecode but no error message Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] Type "help", "copyright", "credits" or "license" for more information. [evaluate derek.py] 1 0 LOAD_CONST 3 ((5, 8)) 3 UNPACK_SEQUENCE 2 6 STORE_NAME 0 (a) 9 STORE_NAME 1 (b) 2 12 LOAD_NAME0 (a) 15 PRINT_ITEM 16 PRINT_NEWLINE 3 17 LOAD_NAME1 (b) 20 PRINT_ITEM 21 PRINT_NEWLINE 4 22 SETUP_LOOP 19 (to 44) 25 LOAD_NAME0 (a) 28 GET_ITER >> 29 FOR_ITER11 (to 43) 32 STORE_NAME 2 (x) 5 35 LOAD_NAME2 (x) 38 PRINT_ITEM 39 PRINT_NEWLINE 40 JUMP_ABSOLUTE 29 >> 43 POP_BLOCK >> 44 LOAD_CONST 2 (None) 47 RETURN_VALUE If I addexec codeto the end of that program I Do get an error, after it prints a and b, but that's separate from the compile statement: exec code Traceback (most recent call last): File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 13, in File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 4, in #print 'Exiting sandbox process' TypeError: 'int' object is not iterable ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] making a string
On 26 May 2013 17:38, eryksun wrote: > On Sun, May 26, 2013 at 8:20 PM, Steven D'Aprano wrote: >> On 27/05/13 07:40, Jim Mooney wrote: >> >>> Good to know that compile doesn't check syntax, since I erroneously >>> thought it did. >> >> compile does check syntax. > > Attempting to iterate an integer is a runtime TypeError, not a > compile-time SyntaxError. Ah, that clears it up. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] keyboard interrupt
>> Bad programming advice is bad enough, but putting up bad advice to >> edit the Windows registry is Really, Really bad. > > Did you leave a comment with the correction? Good point. I wasn't registered on that board but I should go find it. Not that the mistype in that case could possibly cause a registry crash. It just didn't work since a backslash in the path to windows\shellnew was missing, probably due to typing too fast. -- Jim Mooney There are those who see. Those who see when they are shown. And those who do not see. -- Leonardo da Vinci ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] bytecode primer, and avoiding a monster download
I was looking at the bytecode doc page as a break from the Lutz book, since I like Assembler-type code due to its total non-ambiguity, but the page doesn't say much. Is there a doc somewhere that corresponds some of the bytecode to Python source? I thought rot_1, 2, 3, and 4 looked useful, but it would take awhile to disassemble random programs to see what source they come from. Another question. I tried installing a package that back-compiles (in win 7), so I could see things that way, and got the error "Unable to find vcvarsall.bat" Looking around it said I needed to install Visual Studio (Express, of course ;'). I'm on a very slow connection, right now. Is there any alternative to downloading this monster 600 Mb ISO just to install a package, or am I doomed to getting Visual Studio? -- Jim Mooney Atlantis Anyone? http://www.pnas.org/content/early/2013/05/17/1301760110.abstract?sid=8313cec8-3ee0-47a0-9488-5bc33983b081 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor