Re: [Tutor] What’s the differences between these two pieces of code ?

2012-07-13 Thread eryksun
On Sat, Jul 7, 2012 at 12:59 AM, redstone-cold wrote: > > for i in range(1, 7): > > print(2 * i, end=' ') The HTML attachment was scrubbed: http://mail.python.org/pipermail/tutor/attachments/20120707/855bd6ce/attachment-0001.html Here's the troublesome 'indent': Please post using plain text

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread eryksun
On Thu, Jul 19, 2012 at 1:41 AM, wolfrage8...@gmail.com wrote: > > I was comparing them but I think I understand how to compare them well, now > I want to convert them both to binary so that I can XOR them together. Thank > you for your time and help Dave, now I need to reply to Ramit. A bytes ob

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread eryksun
On Thu, Jul 19, 2012 at 3:08 PM, Jordan wrote: > > size = 8 * max(len(b3), len(b4)) > format(r, "0%db" % size) >> '0011001100110011' > Is this output the output for size rather than the two variables joined > together? Using "format" is useful if you need the string to be

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread eryksun
On Thu, Jul 19, 2012 at 5:32 PM, Jordan wrote: > > I am not sure how to answer that question because all files are binary, > but the files that I will parse have an encoding that allows them to be > read in a non-binary output. But my program will not use the in a > non-binary way, that is why I p

Re: [Tutor] string to binary and back... Python 3

2012-07-20 Thread eryksun
On Fri, Jul 20, 2012 at 3:16 AM, Alan Gauld wrote: > On 20/07/12 06:48, wolfrage8...@gmail.com wrote: > > Using the format method it would look like: > > newhexdata = bytes("{0:x}".format(numdata), "ascii") binascii.unhexlify needs an even number of hexadecimal digits (two per byte). So you need

Re: [Tutor] Original indices after Sorting

2012-07-23 Thread eryksun
On Mon, Jul 23, 2012 at 4:02 PM, Ali Torkamani wrote: > By the way, I myself, have this solution: > >> How can we get the indices of values in the original list after sorting a >> list? >> > > (Pdb) A=[ 1, -1, 0, 7, 9, 1.3, 2.9 ] > (Pdb) sorted(zip(A, range(len(A))), key = lambda x: x[0]) > [(-1,

Re: [Tutor] Flatten a list in tuples and remove doubles

2012-07-28 Thread eryksun
On Sat, Jul 28, 2012 at 11:12 AM, Francesco Loffredo wrote: > > I had to study carefully your present and desired lists, and I understood > what follows (please, next time explain !): > - each 7-tuple in your present list is a record for some measure relative to > a person. Its fields are as follo

Re: [Tutor] Flatten a list in tuples and remove doubles

2012-07-28 Thread eryksun
On Sat, Jul 28, 2012 at 7:12 PM, Francesco Loffredo wrote: > > My bad, now I'll RTFM again and I will study very carefully the operator and > itertools modules. I forgot to mention a gotcha about groupby's implementation. The grouby object and the yielded _grouper objects share a single iterator.

Re: [Tutor] Flatten a list in tuples and remove doubles

2012-07-29 Thread eryksun
On Sun, Jul 29, 2012 at 7:21 AM, Peter Otten <__pete...@web.de> wrote: > > If you don't have to deal with large datasets many of its functions can > easily be emulated with lists and loops though. As an example here's the > grouping with a plain vanilla dict: > > groups = {} > for item in data: >

Re: [Tutor] Flatten a list in tuples and remove doubles

2012-07-29 Thread eryksun
On Sun, Jul 29, 2012 at 4:29 PM, Peter Otten <__pete...@web.de> wrote: > > If you have to sort your data anyway you can sort it first and then apply > itertools.groupby()... That was my thinking. I wrote it with groupby (see link below) because Francesco described field 0 as "in growing order". h

Re: [Tutor] finally without try or except

2012-07-30 Thread eryksun
On Mon, Jul 30, 2012 at 3:10 PM, Tino Dai wrote: > On Mon, Jul 30, 2012 at 1:52 PM, Mark Lawrence > wrote: > >> Sorry I'm not completely sure what you're asking for but will this help >> http://docs.python.org/library/atexit.html ? >> > I think this might be what I'm looking for. But for about 2

Re: [Tutor] ImportError

2012-07-31 Thread eryksun
On Tue, Jul 31, 2012 at 10:32 AM, Tino Dai wrote: > > File "/home/tdai/ProjectOne-TNT/leg_apps/etl/transfers/__init__.py", line > 8, in > from api import models > File "/home/tdai/ProjectOne-TNT/leg_apps/api/models.py", line 20, in > > from etl.transfers import eastern > ImportError:

Re: [Tutor] __new__ and __init__

2012-08-01 Thread eryksun
On Wed, Aug 1, 2012 at 11:10 AM, Hugo Arts wrote: > On Wed, Aug 1, 2012 at 4:28 PM, rail shafigulin > > * small caveat: I'm entirely unsure of this, but I *think* if you create > CarModel with a metaclass that overrides __call__ you can change the way > __new__ and __init__ work? If anyone can co

Re: [Tutor] adding a windows registry value

2012-08-03 Thread eryksun
On Fri, Aug 3, 2012 at 10:39 AM, Albert-Jan Roskam wrote: > Hi, > > I am trying to change a registry value (Windows 7, Python 2.7) but it won't > work when I try to do this using Python: > > import os > # 1 using this from Python won't work, but double-clicking the file works. > os.system(r"regedi

Re: [Tutor] adding a windows registry value

2012-08-03 Thread eryksun
On Fri, Aug 3, 2012 at 6:28 PM, Alan Gauld wrote: > > The problem with the reply goes to list approach is that replying to a > poster individually becomes very tedious - you have to manually remove the > unwanted addresses. > > Of course the best solution is to have a client that recognises lists

Re: [Tutor] adding a windows registry value

2012-08-03 Thread eryksun
On Fri, Aug 3, 2012 at 10:39 AM, Albert-Jan Roskam wrote: > > import os > # 1 using this from Python won't work, but double-clicking the file works. > os.system(r"regedit /s C:\Users\Desktop\set_temp.reg") Do you have a user named Desktop, or was this supposed to be "C:\Users\USER_NAME\Desktop\se

Re: [Tutor] Script won't run for no apparent reason

2012-08-10 Thread eryksun
On Fri, Aug 10, 2012 at 6:10 PM, Martin A. Brown wrote: > > : values = {'a':'d', 'b':'e', 'c':'f', 'd':'g', 'e':'h', 'f':'i', 'g':'j', > : 'h':'k', 'i':'l', 'j':'m', 'k':'n', 'l':'o', 'm':'p', 'n':'q', 'o':'r', > : 'p':'s', 'q':'t', 'r':'u', 's':'v', 't':'w', 'u':'x', 'v':'y', 'w':'z', > : 'x'

Re: [Tutor] pickle problems

2012-08-11 Thread eryksun
On Sat, Aug 11, 2012 at 6:30 PM, Richard D. Moores wrote: > > I wrote pickle_attempt.py as an exercise to try to learn to use the > pickle module. See the version I edited for Tutor, > pickle_attempt_for_web.py at > . > > But after closing the program and restart

Re: [Tutor] pickle problems

2012-08-11 Thread eryksun
On Sat, Aug 11, 2012 at 9:18 PM, eryksun wrote: > > On line 68 you open the file in 'ab' mode. A pickle stream ends with > an ASCII period (\x2e). Anything appended after that is ignored. Use > 'wb' mode. Also, Python 3.x defaults to protocol 3, which is bi

Re: [Tutor] pickle problems

2012-08-11 Thread eryksun
On Sat, Aug 11, 2012 at 10:43 PM, Richard D. Moores wrote: > > Changing to 'wb' mode and using the file extension .dat completely > corrected the problems, it seems. Line 69 now reads, > f = open("factors.dat", 'wb') The extension doesn't affect anything about the file. It's just .txt indicates a

Re: [Tutor] pickle problems

2012-08-11 Thread eryksun
On Sat, Aug 11, 2012 at 11:19 PM, Richard D. Moores wrote: > >> To clarify, you can store multiple pickles in a file, but each needs >> its own load. So you'd have to maintain a session dictionary for the >> factors of new integers. Then append the pickled session to the file >> when the user quit

Re: [Tutor] pickle problems

2012-08-12 Thread eryksun
On Sun, Aug 12, 2012 at 4:44 AM, Richard D. Moores wrote: > > OK, thanks for the code, which I will duly study. However, I just > pasted my new version, pickle_attempt_for_web2.py at > . I've tested it and tested it, and it > does exactly what I wanted (thanks to you!

Re: [Tutor] pickle problems

2012-08-12 Thread eryksun
On Sun, Aug 12, 2012 at 7:44 AM, Richard D. Moores wrote: > > I just discovered > os.path.getsize('factors.txt') > and that factors.txt has a size of 2 bytes when "empty". > (I changed the file extension to .txt so I could delete the contents.) No, an empty file has no data; the size is 0. You mu

Re: [Tutor] pickle problems

2012-08-12 Thread eryksun
On Sun, Aug 12, 2012 at 8:46 AM, eryksun wrote: > > t = threading.Thread(target=factorsOfInteger, args=(n, qin, qout)).start() Sorry I need to proofread better. That should be the following: t = threading.Thread(target=factorsOfInteger, args=(n, qin, qout)) t

Re: [Tutor] pickle problems

2012-08-12 Thread eryksun
On Sun, Aug 12, 2012 at 10:58 AM, Dave Angel wrote: > > 2) You wind up with a floating point number. If you're getting floats, > then you're limited to their precision, maybe 18 digits, and limited to > their speed. Perhaps you need to use the // divide rather than the / > one. And perhaps it'd

Re: [Tutor] output not in ANSI

2012-08-13 Thread eryksun
On Mon, Aug 13, 2012 at 2:04 PM, Joel Goldstick wrote: > > I believe in this context the OP means ASCII. ASCII became an ANSI > recognized standard many years ago In Windows, ANSI refers to the locale-dependent 8-bit codepage. But there is no ANSI standard for Windows1252. It's a common misnomer

Re: [Tutor] overriding instance attributes with keywords

2012-08-13 Thread eryksun
On Mon, Aug 13, 2012 at 3:13 PM, Gregory, Matthew wrote: > > I'm trying to create a new instance from an existing instance > def new_with_overrides(s1, **kwargs): > new_params = {'a': s1.a, 'b': s1.b} > for (k, v) in kwargs.iteritems(): > if k in new_params: > new_para

Re: [Tutor] overriding instance attributes with keywords

2012-08-14 Thread eryksun
On Mon, Aug 13, 2012 at 10:28 PM, Steven D'Aprano wrote: > >> def new_with_overrides(obj1, **kwds): >> obj2 = obj1.__new__(obj1.__class__) >> obj2.__dict__.update(obj1.__dict__) >> for k, v in kwds.items(): >> if k in obj2.__dict__: >> obj2.__dict__[k] = v >>

Re: [Tutor] overriding instance attributes with keywords

2012-08-14 Thread eryksun
On Tue, Aug 14, 2012 at 6:01 AM, eryksun wrote: > > Right, I overlooked classes with __slots__ and that override __new__ > and other special methods. copy() is the better and more customizable > solution. If copying is good enough, then this should work: from copy impo

Re: [Tutor] output not in ANSI, conversing char set to locale.getpreferredencoding()

2012-08-14 Thread eryksun
On Tue, Aug 14, 2012 at 10:03 AM, Peter Otten <__pete...@web.de> wrote: > > You have to find out the database encoding The character at 7 is 'ë', which is '\xc3\xab' in UTF-8. So that's likely the db encoding. > As you now have a bytestring again you can forget about codecs.open() which > won't w

Re: [Tutor] overriding instance attributes with keywords

2012-08-14 Thread eryksun
On Tue, Aug 14, 2012 at 2:25 PM, Matt Gregory wrote: > > Thanks to you both for really helpful advice. A quick follow-up question - > would you want to create a deepcopy of obj1 in the above example if your > obj1 contained other objects? I think that Steven's class method gets > around this? C

Re: [Tutor] Confusion regarding the 'from' statement

2012-08-14 Thread eryksun
On Tue, Aug 14, 2012 at 2:24 PM, Mazhar Hussain wrote: > > #mod1.py > from mod2 import test > test('mod1.py') > > #mod2.py > def countLines(name): > print len(open(name).readlines()) > > def countChars(name): > print len(open(name).read()) > > def test(name): > print 'loading...' >

Re: [Tutor] Confusion regarding the 'from' statement

2012-08-14 Thread eryksun
On Tue, Aug 14, 2012 at 9:04 PM, Dave Angel wrote: > > 1) recursive imports. If anybody has a non-trivial top-level code, or > even certain class-initialization code, this can cause surprising errors. Yes, it's a problem if you try to "from" import an object that hasn't been defined yet or use

Re: [Tutor] FW: output not in ANSI, conversing char set to locale.getpreferredencoding()

2012-08-16 Thread eryksun
On Thu, Aug 16, 2012 at 7:33 AM, leon zaat wrote: > > Tried it with: > openbareruimtenaam = openbareruimtenaam1.decode("UTF-8").encode("cp1252") > but still the complains about the ascii error Did you also change it for woonplaatsnaam? For example: import locale file_encoding = locale.getpr

Re: [Tutor] specifying my "default" python installation

2012-08-17 Thread eryksun
On Fri, Aug 17, 2012 at 11:05 AM, Prasad, Ramit wrote: > > I am not really familiar with BSD but *nix has the application > update-alternatives. That will do what you want. Otherwise, > you could change the name/location in the bin directory. > It is likely that python is a symlink to python2.6 an

Re: [Tutor] Error in apparently correct code

2012-08-21 Thread eryksun
On Mon, Aug 20, 2012 at 11:21 PM, Steven D'Aprano wrote: > > Indentation has meaning in Python. When you send email, if your email > program (possibly GMail?) mangles the indentation, your code will become > invalid, unreadable mess. You need to fix this. Often the easiest way to fix > this is to

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread eryksun
On Wed, Aug 22, 2012 at 3:06 AM, Peter Otten <__pete...@web.de> wrote: > > wanted = [line.strip("\n") for line in lines > if "vn" not in line and "vt" not in line and line != "\n"] Here's an equivalent expression with the negation factored out: not ("vn" in line or "vt"

Re: [Tutor] Question

2012-08-23 Thread eryksun
On Thu, Aug 23, 2012 at 1:02 PM, Ashley Fowler wrote: > > Instructions: Your "main" function should do the following: > (1) create an empty list; > (2) ask the user if he/she wants to perform a list operation. > if "yes": > (a) prompt the user for the operation: > "tes

Re: [Tutor] how to split/partition a string on keywords?

2012-08-23 Thread eryksun
On Thu, Aug 23, 2012 at 3:05 PM, Jared Nielsen wrote: > Hi all, > I'm new to programming and Python. > I want to write a script that takes a string input and breaks the string at > keywords then outputs the pieces on separate lines. This is just for printing? You can use replace(): >>> text = "H

Re: [Tutor] how to split/partition a string on keywords?

2012-08-23 Thread eryksun
On Thu, Aug 23, 2012 at 4:03 PM, David Rock wrote: > text = raw_input("Enter text: ") > sep = 'and' > parts = text.split(sep) > for i in parts[:-1]: > print i > print sep > print [-1] >>> "band".split("and") ['b', ''] It needs to be sep = " and ". That's assuming we're ignoring t

Re: [Tutor] how to split/partition a string on keywords?

2012-08-23 Thread eryksun
On Thu, Aug 23, 2012 at 5:25 PM, Alan Gauld wrote: > > To use partition just call it repeatedly until the last string is empty. As > ever the >>> prompt is your friend: > st = 'here we go and there you are and we all go roundabout' h,s,t = st.partition(' and') results = [h,s] w

Re: [Tutor] how to split/partition a string on keywords?

2012-08-23 Thread eryksun
On Thu, Aug 23, 2012 at 9:08 PM, wrote: > s.dir() > Surely you mean dir(s). Maybe you're thinking of the __dir__ special method you can add to a class to override the default behavior. You can also dir(str), or call help(str) to page through all of the doc strings. ___

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-23 Thread eryksun
On Thu, Aug 23, 2012 at 9:39 PM, Dave Angel wrote: > >> theGoodLines = [line.strip("\n") for line in lines if "v " == >> line[0:2]] > > Better to use startswith(), since short lines will cause the if > expression above to blow up. A slice won't blow up. At worst you get an empty string. But t

Re: [Tutor] Python working with Bash....arrrggggh!

2012-08-23 Thread eryksun
On Thu, Aug 23, 2012 at 11:55 PM, Ray Jones wrote: > For example, if I wish to test if a file exists, I might do > > test = Popen('[ -f file-i-want-to-test-for ]') > > But the moment I invoke Bash for a test, I must deal with the fact that > Bash returns a zero for true and a non-zero for false.

Re: [Tutor] better way to write this code

2012-08-24 Thread eryksun
On Thu, Aug 23, 2012 at 2:33 PM, Norman Khine wrote: > > import operator, json > from BeautifulSoup import BeautifulSoup If you have the source of TABLE_CONTENT, why don't you soup that instead? Otherwise, nevermind. > combos={0: 'id', > 2: 'country', > 3: 'type', > 5: 'lat', > 6: 'lon', > 12: '

Re: [Tutor] better way to write this code

2012-08-24 Thread eryksun
On Fri, Aug 24, 2012 at 8:11 AM, Peter Otten <__pete...@web.de> wrote: > > for index, name, fixer in fixers: > item = event[index] @Norman I forgot to mention this. You should index the event instead of iterating over it. I suppose each event has a name in index 12, so you shou

Re: [Tutor] how to split/partition a string on keywords?

2012-08-24 Thread eryksun
On Fri, Aug 24, 2012 at 1:30 PM, Jared Nielsen wrote: > > But if I run the following: > > > #!/usr/bin/python > > text = raw_input("Enter text: ") > > text.replace("and", "\nand") > text.replace("or", "\nor") > > print text > > I get the text as it was entered. > Is there a way to replace text in

Re: [Tutor] creating a subclass from superclass without __init__

2012-08-24 Thread eryksun
On Fri, Aug 24, 2012 at 4:03 PM, Matt Gregory wrote: > > There are two classes of interest in GDAL - a Dataset which typically > describes a geospatial raster file and Band which described a single band > from the Dataset. gdal.Band just raises an AttributeError within __init__, > but a gdal.Band

Re: [Tutor] reason(s) for trailing comma in dict declarations

2012-08-25 Thread eryksun
On Sat, Aug 25, 2012 at 11:53 AM, wrote: > > Put each entry on its own line, indented by two spaces, and leave a > trailing comma on the last entry. The latter is especially important > in sequences of strings to prevent them from being > "silently"<=>"concatenated" if you were to add an entry an

Re: [Tutor] reason(s) for trailing comma in dict declarations

2012-08-25 Thread eryksun
On Sat, Aug 25, 2012 at 1:39 PM, Alan Gauld wrote: > > two adjacent strings without a comma get combined into a single string. > Its a feature... mainly a remnant from the C foundations I suspect. As a feature it can come in handy with long strings in expressions. Just for reference about the "C

Re: [Tutor] 2.7.3 Popen argument issues

2012-08-25 Thread eryksun
On Sat, Aug 25, 2012 at 8:46 PM, Ray Jones wrote: > > Here is my Python call to vlc (error response to follow): > > vlcExec = sp.Popen(['vlc', 'http://' + ip + ':' + port, '-I dummy', > '--sout > \'#duplicate{dst="transcode{vb=400}:std{access=file,mux=avi,dst=outFile > + '.avi}",dst="std{access=ht

Re: [Tutor] 2.7.3 Popen argument issues

2012-08-25 Thread eryksun
On Sat, Aug 25, 2012 at 11:02 PM, eryksun wrote: > > import subprocess > > ip = "192.168.0.2" > port = "1234" > > out_file = "testing.avi" > out_ip = "127.0.0.1" > out_port = "11300" > dst_file = '"transco

Re: [Tutor] askopenfilename - columns missing in navigationwindow

2012-08-25 Thread eryksun
On Sat, Aug 25, 2012 at 9:56 PM, Joel Levine wrote: > > from tkFileDialog import askopenfilename > fn=askopenfilename() > > I use this program repeatedly. Up to a few hours ago, the navigation window > opened with a full array of columns, including name and date. > > Once I mistakenly typed cont

Re: [Tutor] 2.7.3 Popen argument issues

2012-08-25 Thread eryksun
On Sat, Aug 25, 2012 at 11:02 PM, eryksun wrote: > > out_file = "testing.avi" > out_ip = "127.0.0.1" > out_port = "11300" > dst_file = '"transcode{vb=400}:std{access=file,mux=avi,dst=%s}"' % out_file > dst_http = '"std{

Re: [Tutor] 2.7.3 Popen argument issues

2012-08-26 Thread eryksun
On Sun, Aug 26, 2012 at 7:55 AM, Ray Jones wrote: > > [0x8d42554] stream_out_standard stream out error: no mux specified or > found by extension > [0x8d42134] main stream output error: stream chain failed for > `standard{mux="",access=""#duplicate{dst="transcode{vb=400}",dst="std{access=file,mux=a

Re: [Tutor] calculation issue.

2012-08-26 Thread eryksun
On Sun, Aug 26, 2012 at 2:09 PM, Matthew Ngaha wrote: > > heres the code: self.time_til_drop = int(new_pizza.height * 1.3 / > Pizza.speed) + 1 height / speed is the number of steps it takes for a pizza to fall its complete height. It sets time_til_drop to approximately 130% of that number (with a

Re: [Tutor] calculation issue.

2012-08-26 Thread eryksun
On Sun, Aug 26, 2012 at 4:36 PM, eryksun wrote: > > it's 0. Once it's 0, a new pizza is created to be dropped. The > designer wants a 30% buffer (in steps) between the time one pizza has > finished dropping and the creation of a new pizza. To clarify, say the chef is at y=1

Re: [Tutor] calculation issue.

2012-08-26 Thread eryksun
On Sun, Aug 26, 2012 at 5:56 PM, Alan Gauld wrote: > > For a 60px pizza that means a gap of 79 pixels approx. Just to be clear, it's a gap of 79 pixels between the top y coordinates, not between the bottom of one pizza and the top of the other. The latter gap is 79 - 60 = 19 pixels, or a 31.67% b

Re: [Tutor] calculation issue.

2012-08-26 Thread eryksun
On Sun, Aug 26, 2012 at 5:56 PM, Alan Gauld wrote: > > For a 60px pizza that means a gap of 79 pixels approx. Just to be clear, it's a gap of 79 pixels between the top y coordinates, not between the bottom of one pizza and the top of the other. The latter gap is 79 - 60 = 19 pixels, or a 31.67% b

Re: [Tutor] calculation issue.

2012-08-26 Thread eryksun
On Sun, Aug 26, 2012 at 6:19 PM, Matthew Ngaha wrote: > > if this Pizza (pizza.b) was on hold at position y = 100 and the > previous pizza(pizza.a) had fallen an additional 132 pixels to 232 > before pizza.b was released, shouldn't pizza.b still only be at > position y = 100? how did it gain the a

Re: [Tutor] 2.7.3 Popen argument issues

2012-08-27 Thread eryksun
On Mon, Aug 27, 2012 at 3:52 AM, Ray Jones wrote: > > Yes, the Bash call worked (in fact I tried it just prior to sending the > original message just to be sure). > > I guess I'm a bit confused about 'splitting' the arguments. You said > that Python splits arguments on spaces. What exactly happens

Re: [Tutor] Why begin a function name with an underscore

2012-08-28 Thread eryksun
On Tue, Aug 28, 2012 at 6:00 AM, Peter Otten <__pete...@web.de> wrote: > > Anyway here's an alternative implementation: > def vi(x): > ... if not isinstance(x, numbers.Number): > ... raise TypeError > ... if not int(x) == x: > ... raise ValueError You could tes

Re: [Tutor] Why begin a function name with an underscore

2012-08-28 Thread eryksun
On Tue, Aug 28, 2012 at 9:08 AM, Peter Otten <__pete...@web.de> wrote: > > That would reject "floats with an integral value" and therefore doesn't > comply with the -- non-existing -- spec. Gotcha. >> >>> import numbers >> >>> isinstance("42", numbers.Integral) >> False >> >>> num

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread eryksun
On Tue, Aug 28, 2012 at 2:39 PM, Ray Jones wrote: > >> Do you have multiple python installations on your machine? Do you run >> easy_install in one and ipython in another? > > Perhaps. But the module is not accessible from the 'python' shell, from > 'idle', or from iPython. > > As I peruse Synapti

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread eryksun
On Tue, Aug 28, 2012 at 4:00 PM, Ray Jones wrote: > > Oops. No, I see that /usr/local/lib/python2.7/dist-packages is included > in the sys.path. Now what? Good, but does sys.path contain /usr/local/lib/python2.7/dist-packages/pytz-2012d-py2.7.egg? ___ T

Re: [Tutor] Why begin a function name with an underscore

2012-08-30 Thread eryksun
On Thu, Aug 30, 2012 at 4:44 AM, Peter Otten <__pete...@web.de> wrote: > sum(["a", "b", "c"], "") > Traceback (most recent call last): > File "", line 1, in > TypeError: sum() can't sum strings [use ''.join(seq) instead] > > gives me the creeps even though it'd never occur to me to actually

Re: [Tutor] Why begin a function name with an underscore

2012-08-30 Thread eryksun
On Thu, Aug 30, 2012 at 2:07 PM, Peter Otten <__pete...@web.de> wrote: > > Allowing floats for a primality test is a can of worms anyway. You will > inevitably run out of significant digits: Allowing floats can also lead to type errors for operations that require an integral type, but at least the

Re: [Tutor] Problem caused by installing 2.7.3

2012-08-31 Thread eryksun
On Fri, Aug 31, 2012 at 12:49 PM, Richard D. Moores wrote: > > MS Windows 7 Home Premium 64-bit SP1 > > I have some useful (to me) scripts that I use frequently, that I call > with Windows shortcut keys. They used to open in a nice cmd.exe window > I'd configured to my liking. Now I find that they

Re: [Tutor] Tutor Digest, Vol 102, Issue 98

2012-08-31 Thread eryksun
On Fri, Aug 31, 2012 at 8:20 PM, Steven D'Aprano wrote: > > Sequence > The generalisation of lists, tuples and strings. Any object that has > a known length where individual items can be retrieved with the > __getitem__ method called sequentially: obj[0], obj[1], obj[2], ... To expand on th

Re: [Tutor] List all possible 10digit number

2012-08-31 Thread eryksun
On Fri, Aug 31, 2012 at 9:08 PM, Scurvy Scott wrote: > > My question is this- I've been trying for a month to generate a list of > all possible 10 digit numbers. I've googled, looked on stackoverflow, > experimented with itertools, In itertools, look at count() and islice(). An alternative to isl

Re: [Tutor] List all possible 10digit number

2012-08-31 Thread eryksun
On Sat, Sep 1, 2012 at 12:29 AM, Scurvy Scott wrote: > > The while loop works for simply printing. Now I'm trying to save to a file > > I = 10 > Boogers = raw_input("file") > Baseball = open(Boogers) As ASCII, that's 11 bytes per number times 9 billion numbers. That's approximately 92 GiB

Re: [Tutor] List all possible 10digit number

2012-09-01 Thread eryksun
On Sat, Sep 1, 2012 at 3:18 AM, Dave Angel wrote: > > Somehow i missed the point that xrange() is NOT necessarily limited to > Python int values. So it may be usable on your machine, if your Python > is 64bit. All I really know is that it works on mine (2.7 64bit, on > Linux). See the following qu

Re: [Tutor] using multiprocessing efficiently to process large data file

2012-09-01 Thread eryksun
On Sat, Sep 1, 2012 at 9:14 AM, Wayne Werner wrote: > > with open('inputfile') as f: > for line1, line2, line3, line4 in zip(f,f,f,f): > # do your processing here Use itertools.izip_longest (zip_longest in 3.x) for this. Items in the final batch are set to fillvalue (defaults to None)

Re: [Tutor] 2.7.3 generator objects

2012-09-02 Thread eryksun
On Sun, Sep 2, 2012 at 1:44 AM, Ray Jones wrote: > > I was playing with os.walk today. I can use os.walk in a for loop (does > that make it an iterator or just an irritable? ^_^), The output from os.walk is a generator, which is an iterator. os.walk actually calls itself recursively, creating a c

Re: [Tutor] using multiprocessing efficiently to process large data file

2012-09-02 Thread eryksun
On Sun, Sep 2, 2012 at 2:41 AM, Alan Gauld wrote: > >> if __name__ == '__main__': # <-- required for Windows > > Why? > What difference does that make in Windows? It's a hack to get around the fact that Win32 doesn't fork(). Windows calls CreateProcess(), which loads a fresh interpreter. mul

Re: [Tutor] 2.7.3 generator objects

2012-09-02 Thread eryksun
On Sun, Sep 2, 2012 at 3:09 AM, Ray Jones wrote: > > But didn't I read somewhere that you can reset an iterator to go through > the whole process again? You could implement that ability in your own objects, but it's not part of the protocol. I forgot to mention generator expressions. This is an

Re: [Tutor] Fwd: Running a script in the background

2012-09-02 Thread eryksun
On Sun, Sep 2, 2012 at 10:06 AM, Walter Prins wrote: > > nohup python myscript.py & > > Then you can close the terminal afterwards. "nohup" means"no hangup". > It tells the system that the python process launched as a result of > this command should not be terminated when its parent shell is > t

Re: [Tutor] Running a script in the background (this time Cc'd to the list)

2012-09-02 Thread eryksun
On Sun, Sep 2, 2012 at 9:04 PM, William R. Wing (Bill Wing) wrote: > > Apple's mechanism for launching applications at login is picky > about what it will accept as a legitimate application to add to > the list. Here's an Ask Different (Apple Stack Exchange) answer with a template for a launchd

Re: [Tutor] Running a script in the background

2012-09-04 Thread eryksun
On Mon, Sep 3, 2012 at 10:21 PM, Dwight Hutto wrote: > What's wrong with: > > But each OS(BIOS handler) has a way of providing/accepting instructions to > the processor, which is constantly procedural. This has to have a terminal > at some point. What do you mean by 'terminal' in this context? A

Re: [Tutor] making a shortcut in windows

2012-09-04 Thread eryksun
On Mon, Sep 3, 2012 at 9:57 PM, Garry Willgoose wrote: > I want to put a shortcut onto the desktop in windows (XP and later) in > > AttributeError: function 'CreateSymbolicLinkW' not found A simple search for "msdn CreateSymbolicLink" leads to the following page: http://msdn.microsoft.com/en-us/

Re: [Tutor] Unicode? UTF-8? UTF-16? WTF-8? ;)

2012-09-05 Thread eryksun
On Wed, Sep 5, 2012 at 5:42 AM, Ray Jones wrote: > I have directory names that contain Russian characters, Romanian > characters, French characters, et al. When I search for a file using > glob.glob(), I end up with stuff like \x93\x8c\xd1 in place of the > directory names. I thought simply identi

Re: [Tutor] Unicode? UTF-8? UTF-16? WTF-8? ;)

2012-09-05 Thread eryksun
On Wed, Sep 5, 2012 at 10:51 AM, Ray Jones wrote: > > subprocess.call(['dolphin', '/my_home/testdir/\u044c\u043e\u0432']) > > Dolphin's error message: 'The file or folder > /my_home/testdir/\u044c\u043e\u0432 does not exist' "\u" only codes a BMP character in unicode literals, i.e. u"unicode lite

Re: [Tutor] Student Class

2012-09-05 Thread eryksun
On Wed, Sep 5, 2012 at 7:43 PM, Ashley Fowler wrote: > > class Student: Are you using Python 3? If not, Student should explicitly inherit from object. > def __init__(self, first_name, last_name, numCredits, gpa): > self.first_name = first_name > self.last_name = last_name >

Re: [Tutor] Formatting questions regarding datetime.isoformat()

2012-09-06 Thread eryksun
On Wed, Sep 5, 2012 at 11:00 PM, staticsafe wrote: > > In [68]: showinfo['RFC3339'] > Out[68]: '2012-09-10T21:00:00-4:00' You can parse the ISO format using the dateutil module: http://labix.org/python-dateutil >>> from dateutil.parser import parse >>> show_time = parse('2012-09-10T21:0

Re: [Tutor] Hey.need help on time

2012-09-06 Thread eryksun
On Thu, Sep 6, 2012 at 3:21 AM, Keitaro Kaoru wrote: > been trying to change this so it wont use my server time. but my > actual time here in the us.EST. havent been able to figure it out > > def sstime(user, body, m): > os.environ['TZ'] = 'US/Eastern' Now just call time.tzset(), and it s

Re: [Tutor] Formatting questions regarding datetime.isoformat()

2012-09-06 Thread eryksun
On Thu, Sep 6, 2012 at 3:50 AM, Dave Angel wrote: > On 09/06/2012 03:35 AM, eryksun wrote: >> >> Or you could use datetime.now(dateutil.tz.tzutc()) for a UTC tzinfo. >> It doesn't matter if you're only interested in the timedelta. > > Actually, it can ma

Re: [Tutor] Doing the same thing twice. Works first time but not the second.

2012-09-06 Thread eryksun
On Fri, Aug 17, 2012 at 4:11 PM, Matthew Love wrote: > def inventory(self): > self.inventory = ["torch"] > return self.inventory What is 'self.inventory' before you call inventory(), and what is it afterwards? A quick fix would be to name the list "_inventory" and return self.

Re: [Tutor] Hey.need help on time

2012-09-06 Thread eryksun
On Thu, Sep 6, 2012 at 4:25 AM, Ray Jones wrote: > > Why the additional step of calling time.tzset()? Once os.environ['TZ'] > is set, I've found that time.localtime() responds to the new TZ without > anything extra. Is that a difference in versions (2.7.3 here)? It shouldn't strictly be necessary

Re: [Tutor] urllib2.urlopen(....., timeout=)

2012-09-07 Thread eryksun
On Fri, Sep 7, 2012 at 11:32 AM, Dave Angel wrote: > > I'm curious why the docstring says... timeout = > but have no clues for you. socket._GLOBAL_DEFAULT_TIMEOUT is an object(). In other words, it's an "object object". Also, that's not from the docstring but the call signature. The functio

Re: [Tutor] Pygame and TkInter

2012-09-09 Thread eryksun
On Sun, Sep 9, 2012 at 5:58 PM, Greg Nielsen wrote: > Hello Tutor, > > Quick question. Working on a new game and want to build in a GUI. > TkInter seems to fit the bill except for one small item. Both Pygame and > TkInter create windows. (Screen in Pygame, and the Root widget in TkInter) > Is

Re: [Tutor] Pygame and TkInter

2012-09-10 Thread eryksun
On Mon, Sep 10, 2012 at 12:34 PM, Greg Nielsen wrote: > I will admit that the whole Blender project is cool, but Jerry has a point. > All I wanted to know was how to get Pygame and TkInter to work together, and > I got a solid answer about 12 hours ago. (Check out Eryksun's code, it's > beyond coo

Re: [Tutor] Seeing response from authorization page with urllib2

2012-09-11 Thread eryksun
On Tue, Sep 11, 2012 at 4:29 AM, Ray Jones wrote: > > But when I attempt to get any part of an authorization-required page > using urllib2.urlopen(), I immediately receive the 401 error. Even the > intended object variable is left in an undefined state, so using info() > doesn't seem to work. How

Re: [Tutor] Question

2012-09-11 Thread eryksun
On Tue, Sep 11, 2012 at 12:08 PM, Ashley Fowler wrote: > > I have a question. In a assignment it asks for me to do the following > below... > > if "peek" then print the Student object at the beginning > of the list (using __str__) but don't remove it from > the list; >

Re: [Tutor] Constructing a object

2012-09-11 Thread eryksun
On Tue, Sep 11, 2012 at 10:23 PM, Ashley Fowler wrote: > How do you construct a object using variables? > > For instance I have to construct a student object, by first prompting the > user to enter variables for the Student class (their first and last names, > credits and gpa) then construct a Stu

Re: [Tutor] Musical note on python

2012-09-12 Thread eryksun
On Wed, Sep 12, 2012 at 1:17 AM, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote: > How to produce a musical note of given frequency,volume and duration in > Python. Do you just want a sinusoidal, pure tone, or do you need a more complex waveform? For a pure tone you can use math.sin(2 * math.pi * f * dt * n)

Re: [Tutor] Musical note on python

2012-09-12 Thread eryksun
On Wed, Sep 12, 2012 at 4:49 AM, Dwight Hutto wrote: > > pyaudio is compatible with python 3.0(just in case the OP has that > version, and it doesn't look like on the main site it has it listed, > nor if it's 64 bit, etc. I'm surprised they don't have an official Python 3 port yet. I see now the

Re: [Tutor] convert ascii to binary

2012-09-12 Thread eryksun
On Wed, Sep 12, 2012 at 7:20 AM, Aaron Pilgrim wrote: > Hello, > I am trying to write a small program that converts ascii to binary. > > I tried using the python reference library section 18.8 but had > trouble understanding how to make it work. > > Here is the code I am currently trying to use:

Re: [Tutor] setting a timer

2012-09-12 Thread eryksun
On Wed, Sep 12, 2012 at 1:56 PM, Matthew Ngaha wrote: > i have a way to set a timer for creating new objects copied from a > book but as i have started my next exercise in a very different way, i > want to avoid that math method/formula as it will cause me to > rearrange some classes totally... >

Re: [Tutor] Sigh first real python task

2012-09-13 Thread eryksun
On Wed, Sep 12, 2012 at 11:06 PM, Mike S wrote: > try: > ret = subprocess.call("smbclient //reportingmachine/Dashboard/; put > %s\" -U Username%Password" % (fileName), shell=True) > if ret < 0: > print >>sys.stderr, "Child was terminated by signal", -ret >

Re: [Tutor] Musical note on python

2012-09-13 Thread eryksun
On Thu, Sep 13, 2012 at 11:48 AM, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote: > > As far as programming volume is concerned winsound.Beep has only frequency > and duration. pyaudio module appears to have provision for volume control. You should be able to add a wave header to a raw byte string. For example

  1   2   3   4   5   6   7   >