Re: [Tutor] question about operator overloading

2012-03-06 Thread Peter Otten
Dave Angel wrote: > On 03/05/2012 06:20 PM, Alan Gauld wrote: >> On 05/03/12 21:25, Dave Angel wrote: >> >>> It's not clear what __add__() should mean for physical files. >> >> My guess would be similar to the cat operator in Unix: >> >> $ cat file1, file2 > file3 >> >> is equivalent to >> >> file

Re: [Tutor] inserting new lines in long strings while printing

2012-03-07 Thread Peter Otten
Abhishek Pratap wrote: > I have this one big string in python which I want to print to a file > inserting a new line after each 100 characters. Is there a slick way to do > this without looping over the string. I am pretty sure there shud be > something its just I am new to the lang. There is al

Re: [Tutor] getattr help

2012-03-10 Thread Peter Otten
mjole...@gmail.com wrote: > What is the purpose of getattr? Why not just use help or am I completely > misunderstanding this? > >>From what I read, getattr allows you to get a reference to a function >>without knowing its name until runtime. > > However, the example provided is: > > li = ['larr

Re: [Tutor] UnicodeEncodeError: 'cp932' codec can't encode character '\xe9' in position

2012-03-11 Thread Peter Otten
Robert Sjoblom wrote: > Okay, so here's a fun one. Since I'm on a japanese locale my native > encoding is cp932. I was thinking of writing a parser for a bunch of > text files, but I stumbled on even printing the contents due to ... > something. I don't know what encoding the text file uses, which

Re: [Tutor] UnicodeEncodeError: 'cp932' codec can't encode character '\xe9' in position

2012-03-11 Thread Peter Otten
Steven D'Aprano wrote: > glyph. He shouldn't get a UnicodeDecodeError when printing. I smell a > bug since print shouldn't be decoding anything. (At worst, it needs to > *encode*.) You have correctly derived the actual traceback ;) [Robert] > It starts to print until it hits the wonderful charac

Re: [Tutor] commands.getoutput equivalent in subprocess

2012-03-18 Thread Peter Otten
Pete O'Connell wrote: > Hello I print a lot of values at work using grep and need to be > constantly opening a shell window to do this (rather than staying > within my main program which is Nuke by the Foundry). Is there a > simple equilavent to commands.getoutput that is more up to date (I > woul

Re: [Tutor] commands.getoutput equivalent in subprocess

2012-03-19 Thread Peter Otten
> Pete O'Connell wrote: > Hi, I am using Python 2.6 I can't use Python 3 in this particular situation. [Please reply to the list, not in private mail.] You can continue to use commands.getoutput() in 2.6 and 2.7, and once you are ready to make the jump to 3.x replace it with subprocess.getoutp

Re: [Tutor] New to this list ....

2012-03-30 Thread Peter Otten
Barry Drake wrote: > On 30/03/12 16:19, Evert Rol wrote: >> Not sure. In the sense that you can "optimise" (refactor) it in the same >> way you could do with C. Eg: results = [0, 0, 0] >> flags = [0, 1, 2, 3] >> for flag in flags: >> results = getflag(flag, results) >> > > That's exactly wha

Re: [Tutor] Question about login=''.join(choice(lc) for j in range(llen))

2012-04-03 Thread Peter Otten
Alan Gauld wrote: > On 03/04/12 15:54, Khalid Al-Ghamdi wrote: > >> dom="".join(choice(lc) for j in range (dlen)) >> >> how does the interpreter know what "j" is supposed to refer to when it >> was not mentioned prior? > > In Python variables are defined by using them. > > In the code belo

Re: [Tutor] group txt files by month

2012-04-05 Thread Peter Otten
questions anon wrote: > I have been able to write up what I want to do (using glob) but I am not > sure how to loop it or simplify it to make the script more efficient. > I am currently: > -grouping the same months in a year using glob > -opening the files in a group and combining the data using a

Re: [Tutor] regex question

2012-04-05 Thread Peter Otten
Khalid Al-Ghamdi wrote: > I'm trying to extract the domain in the following string. Why doesn't my > pattern (patt) work: > redata > 'Tue Jan 14 00:43:21 2020::eax...@gstwyysnbd.gov::1578951801-6-10 Sat Jul > 31 15:17:39 1993::rz...@wgxvhx.com::744121059-5-6 Mon Sep 21 20:22:37 > 1987::ttw..

Re: [Tutor] Calling Classes From Tkinter Radio Buttons

2012-04-09 Thread Peter Otten
Nathan wrote: > I'm using Tkinter for a GUI for a program of mine, and I'm trying to > use radio buttons to select different functions, but it's not working > right at all. Originally, I had something like > > class ClassOne(self): You didn't run that code. > def ___str___(self): >

Re: [Tutor] user created lists

2012-04-12 Thread Peter Otten
Christian Witts wrote: > On 2012/04/12 06:42 AM, john moore wrote: >> Hello Pyhton World, >> >> I'm new at this and was wondering how I create a number of user specified >> lists? >> >> Example: >> >> "How many list would you like to create?" >> User inputs 5 >> creates five lists, >> list1 [] >>

Re: [Tutor] python connect() function

2012-04-12 Thread Peter Otten
Pierre Barthelemy wrote: > I have a question about event handling and the use of the connect > function. I have a data object, that contains a series of signals, one > being "new_data_point" . > > When i want to plot the data, i also connect the "new_data_point" event to > the function "analysis_

Re: [Tutor] Iterate Suggestion

2012-04-15 Thread Peter Otten
Tom Tucker wrote: > Hello all. Any suggestions how I could easily iterate over a list and > print the output 3 across (when possible)? One method I was considering > was removing the recently printed item from the list, checking list > length, > etc. Based on the remaining length of the list I

Re: [Tutor] Readabilty vs 80 characters

2012-04-19 Thread Peter Otten
Tino Dai wrote: > Hi! > > I have a question about style. In PEP-8, it says don't exceed 79 > characters, but can this rule ever be trumped by > readability? > > Eg. > > > if someobject.filter(something) \ > .filter(somethingreallyreallyreallyreallylong == > somethingelserea

Re: [Tutor] Readabilty vs 80 characters

2012-04-20 Thread Peter Otten
Russel Winder wrote: > On Thu, 2012-04-19 at 16:00 +0200, Peter Otten wrote: > [...] >> Seriously, learn that you don't need backslashes if you put the >> expression into parens, precalculate parts of the expression and put them >> into temporary variables -- and if

Re: [Tutor] events and popup menus

2012-05-03 Thread Peter Otten
Chris Hare wrote: > I have four images in a frame. I want to pop up a menu when the user > right clicks on an image, and when they choose an option from the menu, > execute the action. > > I can create the popup menu, and bind it to the image. However, what I > can't figure out is how to detect

Re: [Tutor] the regex boundary about chinese word

2012-05-04 Thread Peter Otten
goog cheng wrote: > Hi, I got this problem : > > #!python > # -*- coding: utf-8 -*- > import re > > p = re.compile(ur'\bc123\b') > print '**',p.search('no class c123 at all').group() > > p = re.compile(ur'\b\u7a0b\u6770\b') > print ur'\u7a0b\u6770' > print '',p.search(' 程杰 abc'.decode('utf

Re: [Tutor] Sorting the parts of a dictionary into a list

2012-05-06 Thread Peter Otten
Jacob Bender wrote: > Dear tutors, > > I'm trying to create a neural network program. Each neuron is in a > dictionary and each of its connections and their strengths are in a nested > dictionary. So {0:{1:4, 2:5}}, 1:{0:6}, 2:{1:2}} would mean that neuron 0 > is connected to neuron 1 with a stre

Re: [Tutor] error when using using subprocess.popen in Python wrapper script

2012-05-07 Thread Peter Otten
Rogelio wrote: > If I want to write this command to a file, would this be the right format? > > * > import subprocess > > (all my variables defined okay) > > perl_script=subprocess.call(['perl',perl_prog,ipfile,cmd,user,timeout,]) > > log=open('/tmp/pythonOutput

Re: [Tutor] looking for some advice

2012-05-07 Thread Peter Otten
Chris Hare wrote: > Hello Everyone: > > Here is what I am trying to do: > > I have a window which has a row of buttons on it. Below the buttons is a > label frame. Depending upon which button they push, I want to change the > widgets in the label frame. I can add widgets now with no problem.

Re: [Tutor] odd behavior when renaming a file

2012-05-09 Thread Peter Otten
Joel Goldstick wrote: > import os > def pre_process(): > if os.path.isfile('revelex.csv'): > os.rename('revelex.csv', 'revelex.tmp') > print "Renamed ok" > else: > print "Exiting, no revelex.csv file available" > exit() > out_file = open('revelex.csv', '

Re: [Tutor] sqlite3 question

2012-05-24 Thread Peter Otten
Alan Gauld wrote: > On 23/05/12 17:11, Khalid Al-Ghamdi wrote: > >> I'm using Python 3 and have read that you need sqlite to be installed to >> use the sqlite3 module, but when it is imported it seems to work ok. > > The info is wrong. > Unlike other SQL databases SQLite is not a server based sy

Re: [Tutor] (no subject)

2012-06-01 Thread Peter Otten
Jason Barrett wrote: > In python, why does 17/-10= -2? Shouldn't it be -1? http://docs.python.org/faq/programming.html#why-does-22-10-return-3 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.or

Re: [Tutor] Unexpected result of division by negative integer, was: (no subject)

2012-06-02 Thread Peter Otten
Jason Barrett wrote: [Jason, please use "reply all" instead of sending a private mail. Your answer will then appear on the mailing list and other readers get a chance to offer an alternative explanation.] >> In python, why does 17/-10= -2? Shouldn't it be -1? > >> http://docs.python.org/faq/pr

Re: [Tutor] Issue with classes

2012-06-12 Thread Peter Otten
Bod Soutar wrote: > Hi, > > I am having some difficulty calling a class method from a different class. > When I run the attached script like this "python cheatsheet.py --list" > > C:\>python cheatsheet.py --list > done > here? > Traceback (most recent call last): > File "cheatsheet.py", line 1

Re: [Tutor] Python XML for newbie

2012-07-02 Thread Peter Otten
Sean Carolan wrote: >> Thank you, this is helpful. Minidom is confusing, even the >> documentation confirms this: >> "The name of the functions are perhaps misleading" >> >>> But I'd start with the etree tutorial (of which >>> there are many variations on the web): > > Ok, so I read through

Re: [Tutor] Simple text file processing using fileinput module. "Grabbing successive lines" failure

2012-07-03 Thread Peter Otten
Flynn, Stephen (L & P - IT) wrote: > Tutors, > > Whilst having a play around with reading in textfiles and reformatting > them I tried to write a python 3.2 script to read a CSV file, looking for > any records which were short (indicating that the data may well contain an > embedded CR/LF. I've a

Re: [Tutor] Creating a dictionary on user filter

2012-07-20 Thread Peter Otten
Mike Nickey wrote: > What I have is this: > firstList = ['a', 'b', 'c'] > secondList = [1,2,3] > thirdList = [1.20, 1.23, 2.54] > > What I am looking for is something like this for output: > {'a': [1, 1.20], 'b': [2, 1.23], 'c': [3, 2.54]} To get this combine second and third into the list of va

Re: [Tutor] Recreating the help module

2012-07-24 Thread Peter Otten
M Nickey wrote: > Hey all, > > I'm trying to recreate the 'help' on various modules that are available. > So far, I have a bit of code and it seems to be working for the most part. > I can get the modules available but I also want to be able to print the > information that is available for each m

Re: [Tutor] Getting name of Widget for event.widget?

2012-07-25 Thread Peter Otten
Leam Hall wrote: > Note that this is for an on-line class so I'd appreciate pointers to > what I need to read or think about more than the answer out right. > > Using Python 3 on Linux, is there a way to get the name of a widget > instead of numeric representations in event.widget? > > What I tr

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

2012-07-29 Thread Peter Otten
Mark Lawrence wrote: > On 29/07/2012 00:53, Alan Gauld wrote: >> On 29/07/12 00:12, Francesco Loffredo wrote: >> >>> Every time this happens, I have to admit that I'm a newbie and I've >>> still got a lot to learn about Python. Especially about its wonderful >>> standard library. >> >> Don't worry

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

2012-07-29 Thread Peter Otten
eryksun wrote: > 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 >> group

Re: [Tutor] sqlite3 Dilemma

2012-07-30 Thread Peter Otten
Khalid Al-Ghamdi wrote: > I am a teacher at an industrial training center. We have to conduct > hands-on exams (fixing pumps, etc). I review all the test schedules for > all the students (made by other teachers) to make sure there are no > clashes due to lack of ample supply of equipment or tools.

Re: [Tutor] Recursive assignment in nested lists

2012-08-04 Thread Peter Otten
Alonzo Quijote wrote: > Is there a way to define a function which takes >a list (of lists), >a position specified by a list of integers [i0,i1,...,in], and >a value > and returns the result of setting > list[i0][i1]...[in]=value > > The following function works for positions up to

Re: [Tutor] filelist

2012-08-05 Thread Peter Otten
richard kappler wrote: > Starting to work through "Programming Computer Vision with Python" in my > -summer of learning python- quest. As I read through the intro to the PIL > library, I came across the below code. When I read it, I said to my self > "I don't see how that calls a set of files, t

Re: [Tutor] Code Review?

2012-08-06 Thread Peter Otten
Brian Carpio wrote: > Hi, > > Hopefully I am allowed to ask this here. I am pretty new to python I've > only been writing code for about 6 months now strictly for system > administration purposes; however I have now decided to write something > "real" that others might benefit from but I am looki

Re: [Tutor] How to import a few modules when I enter python?

2012-08-07 Thread Peter Otten
Santosh Kumar wrote: > Hello there, > > I have a few scripts that I made to experiment with, I have to import > them everytime I enter the Python shell. The scripts are in > `/home/username/workshop/` (this directory has also some non .py > files) directory. Is there a way I can import them as so

Re: [Tutor] Built in functions

2012-08-07 Thread Peter Otten
Dane Saltzman wrote: > I'm new to python and I was wondering if you could tell me how I would: > > first, define a function,distance_from_zero, with one parameter (choose > any parameter name you like). Second, have that function do the following: > 1. Check the type of the input it receives. >

Re: [Tutor] Question about reading from a file.

2012-08-07 Thread Peter Otten
Brad Dutton wrote: > I recently discovered how to read from a file but I've having some trouble > with it. I made a short example program that goes like this: > > >1. fob = open('c:/python27/a.txt', 'r') >2. >3. print fob.read() >4. print fob.read() > > When it runs it returns t

Re: [Tutor] Unzip a zipfile, then unzip the zipfiles within the original zip

2012-08-07 Thread Peter Otten
Gregory Lund wrote: [For improved readability please avoid # prefixes for the parts of your post that are not comments in snippets of python code] > neophyte .py/pyTutor user. Welcome. > I am also a university GIS lecturer. My students submit their lab > assignments (zipped up into one zipfile

Re: [Tutor] Unzip a zipfile, then unzip the zipfiles within the original zip

2012-08-08 Thread Peter Otten
Gregory Lund wrote: > Not too sure on protocol either, sorry if this email is out of line. You have to hit [Reply all] in your email client for your answer to go to the list instead of just me. When you answer a post put your reply after the relevant part of the quoted post (don't "top-post").

Re: [Tutor] help -Global name xxxxxxxx is not definied.

2012-08-09 Thread Peter Otten
leon zaat wrote: > Hello everyone, > > Can anybody help me with this problem. > Ik have a program that i' am modifying. > > Ik build a function to export data to a csv file. I tried the functions > over different parts, that needed to be extracted. The parts on it self > worked fine. Now I put a

Re: [Tutor] pickle problems

2012-08-12 Thread Peter Otten
Richard D. Moores wrote: > f = open("factors.txt", 'rb') > data = pickle.load(f) > f.close f.close looks up the close method but doesn't invoke it; you need f.close(). Alternatively use a with statement: with open("factors.txt", "rb") as f: data = pickle.load(f) This will close the file eve

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

2012-08-14 Thread Peter Otten
leon zaat wrote: > I get the error: > UnicodeDecodeError: 'ascii' codecs can't decode byte 0xc3 in position 7: > ordinal not in range(128) for the openbareruimtenaam=u'' + > (openbareruimtenaam1.encode(chartype)) line. The error message means that database.select() returns a byte string. bytest

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

2012-08-14 Thread Peter Otten
Mazhar Hussain wrote: > Im new to python and theres something thats bothering me for quite a > time. I read in 'Learning Python' by Mark Lutz that when we use a > 'from' statement to import a name present in a module, it first > imports the module then assigns a new name to it(i.e. the name of the

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

2012-08-15 Thread Peter Otten
Mazhar Hussain wrote: > thanks alot for the help, was really confused with this. > Well what ure > trying to say is that even when a module object is deleted from the > global namespace of a module, a reference of it is still present in > the sys.modules dict? Yes, adding the reference to the

Re: [Tutor] Escaping globs for glob.iglob()

2012-08-20 Thread Peter Otten
Ray Jones wrote: > The code: > > curDir = os.getcwd() > znDir = shutil.abspath('../') > baseDir = shutil.abspath('../../') > > Files = glob.iglob(os.path.join(znDir, '*')) > print Files > > for moveFile in Files: > print moveFile > shutil.move(moveFile, curDir) > > Nothing

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

2012-08-22 Thread Peter Otten
Pete O'Connell wrote: > Hi I am trying to parse a text file and create a list of all the lines > that don't include: "vn", "vt" or are empty. I want to make this as > fast as possible because I will be parsing many files each containing > thousands of lines. I though I would give list comprehensio

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

2012-08-22 Thread Peter Otten
Pete O'Connell wrote: [Please don't to-post. Clip all text of previous posts except the portion relevant to your question] > Hi. The next step for me to parse the file as I want to is to change > lines that look like this: > f 21/21/21 22/22/22 24/24/23 23/23/24 > into lines that look like this:

Re: [Tutor] What are all those letters after terminal commands?

2012-08-23 Thread Peter Otten
Cecilia Chavana-Bryant wrote: > Hola, > > I'm going through the 'Command line crash course' by Zed Shaw, thanks to > the people that recommended this book, its quite a good course, I can see > what the author was going for with the title but if it wasn't for your > recommendations, it would have

Re: [Tutor] Error message...

2012-08-23 Thread Peter Otten
Victoria Homsy wrote: > Sorry to bother you with a beginner's problem again... This is the place for beginners. > I have tried to write a program that can check if a string is a > palindrome. My code is as follows: > > > def isPalindrome(s): > if len(s) <= 1: return True > else: retur

Re: [Tutor] Python 3.2: processing text files in binary mode, because I want to remove carriage returns and line feeds...

2012-08-23 Thread Peter Otten
Flynn, Stephen (L & P - IT) wrote: > Python 3.2, as in the subject, although I also have 2.7 on this machine > too. > > > > I have some data which contains text separated with field delimiters > (|~) and a record terminator (||) > > 12345600990|~5229|~990|~0|~4|~1|~2006-09-08|~13:2

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

2012-08-23 Thread Peter Otten
Pete O'Connell wrote: > Hi, I have tried to simplify things and am running into a bit of trouble. > What i am really trying to do is: Keep all the lines starting with "v " > and then delete those lines whose modulus 5 don't equal zero > > I have written it like this which seems to take a really l

Re: [Tutor] better way to write this code

2012-08-24 Thread Peter Otten
Norman Khine wrote: > I have this code (http://pastie.org/4575790) which pulls data from a list > and then modifies some of the values such as the 'yield' entry, which has > entries like: > > 21 > 15 > ≤ 1000 > ≤ 20 > 2.2 - 30 > > so that they are cleaned up. > can the code be improved furth

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

2012-08-24 Thread Peter Otten
Jared Nielsen wrote: > I implemented eryksun's suggestion and used the replace() method. > But, playing around with it, what I discovered is that it won't store the > change. > For example, when the input text is, "Ham and cheese or chicken and > waffles": > > #!/usr/bin/python > > text = raw_in

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

2012-08-25 Thread Peter Otten
aklei...@sonic.net wrote: > Part of a previous post: > """ > Here's the style I'd use: > > combos = { > 0: 'id', > 2: 'country', > 3: 'type', > 5: 'lat', > 6: 'lon', > 12: 'name', > } > > Put each entry on its own line, indented by two spaces, and leave a > trailing comma on the last

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

2012-08-28 Thread Peter Otten
Timo wrote: > Op 28-08-12 10:06, Richard D. Moores schreef: >> On Tue, Aug 28, 2012 at 12:13 AM, Jerry Zhang >> wrote: >>> >>> 2012/8/28 Richard D. Moores >>> On Mon, Aug 27, 2012 at 6:33 PM, Japhy Bartlett wrote: > something like: > > def _validate_int(obj): >

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

2012-08-28 Thread Peter Otten
Richard D. Moores wrote: > On Tue, Aug 28, 2012 at 1:21 AM, Timo wrote: >> Op 28-08-12 10:06, Richard D. Moores schreef: > >>> What if I wanted 3., 1234., etc. to be considered ints, as they are by >>> _validate_int() ? >> >> > isinstance(3., (int, float)) >> True >> >> Because 3. is a floa

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

2012-08-28 Thread Peter Otten
eryksun wrote: > 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): >> ..

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Peter Otten
Ray Jones wrote: > I'm working on another Python replacement for a Bash script, and I ran > into a need for enhanced time zone functions. Following directions I > found on a web site, I did the following: > > # easy_install --upgrade pytz > Searching for pytz > Reading http://pypi.python.org/simp

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Peter Otten
Ray Jones wrote: > On 08/28/2012 11:06 AM, Peter Otten wrote: >> Ray Jones wrote: >> >>> I'm working on another Python replacement for a Bash script, and I ran >>> into a need for enhanced time zone functions. Following directions I >&g

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

2012-08-30 Thread Peter Otten
Steven D'Aprano wrote: > On 28/08/12 20:00, Peter Otten wrote: > [...] >> The differences to _validate_int() are subtle: >> >>>>> class S(str): >> ... def __eq__(self, other): return True >> ... def __ne__(self, other): return Fals

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

2012-08-30 Thread Peter Otten
Steven D'Aprano wrote: > On 28/08/12 19:02, Peter Otten wrote: >> Personally, I'm a big fan of ducktyping, so I would probably remove the >> check completely and live with the consequences: >> >>>>> >>> pyprimes._validate_int = lambda

Re: [Tutor] checking input parameters

2012-08-31 Thread Peter Otten
Bala subramanian wrote: > I use the following way to check for the input parameters. I would > like to know if there is a any better way to show or describe the > script usage. So when the user just runs it without any input params., > the program shd not execute but just shows the documentation.

Re: [Tutor] 2.7.3 generator objects

2012-09-02 Thread Peter Otten
Steven D'Aprano wrote: > On 02/09/12 17:09, Ray Jones wrote: > >> But didn't I read somewhere that you can reset an iterator to go through >> the whole process again? > > In general, no. > > The usual way to "reset" an iterator is to re-create it. > > > walker = os.walk("/home/steve/start") >

Re: [Tutor] making len() and __len__ return a non-int

2012-09-02 Thread Peter Otten
Albert-Jan Roskam wrote: > If I implement __len__ in my own class, does it really have to return an > int? Is there no way around this (other than modifying the source code of > python itself ;-) It would be nice if len(Example(row, col)) would return > a dictionary, or a two-tuple (see code below

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

2012-09-05 Thread Peter Otten
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 identifying them as Unicode would > cl

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

2012-09-05 Thread Peter Otten
Ray Jones wrote: >> You can work around that by specifying the appropriate encoding >> explicitly: >> >> $ python tmp2.py iso-8859-5 | cat >> � >> $ python tmp2.py latin1 | cat >> Traceback (most recent call last): >>File "tmp2.py", line 4, in >>print u"Я".encode(encoding) >> UnicodeEncodeError:

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

2012-09-05 Thread Peter Otten
Ray Jones wrote: > On 09/05/2012 04:52 AM, Peter Otten wrote: >> Ray Jones wrote: >> >>> >>> But doesn't that entail knowing in advance which encoding you will be >>> working with? How would you automate the process while reading existing >>&

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

2012-09-06 Thread Peter Otten
staticsafe wrote: > Hello, > > I am running Python 2.6.6 on a Debian Squeeze system. I am using two > modules in this bit of code - datetime and python-tvrage (available on > pypy here: http://pypi.python.org/pypi/python-tvrage/). > > My goal is to find the time remaining until a certain show ai

Re: [Tutor] math description

2012-09-06 Thread Peter Otten
damjan kuzmic wrote: > i would like to know how to write a formula that in excell looks like > this: > > A / EXP(-LN(2) * t) >>> import math >>> A = 1.23 >>> t = 4.56 Literally (math.log is the natural logarithm): >>> A / math.exp(-math.log(2) * t) 29.013618196288864 However, exp(-x) == 1

Re: [Tutor] python 2.7.1

2012-09-06 Thread Peter Otten
john wrote: > print "hello world" #this is just something to say /Users/jonathan/Documents/hello.py > File "", line 1 > /Users/jonathan/Documents/hello.py > ^ > SyntaxError: invalid syntax > > what am i doing wrong? The >>> prompt indicates that you have already started the inter

Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Peter Otten
Ray Jones wrote: > I have a multiple 'if' expression that I need to drastically reduce in > size, both for readability and to keep errors from creeping in. > > For example, I would like to have the variable 'test' point to the a > location 'grid[rcount-1][ccount-1]' so that everywhere I would use

Re: [Tutor] group txt files by month

2012-09-07 Thread Peter Otten
questions anon wrote: > Hello All, it has been a few months since I have used this and I have only > just realised I am having problems with leap years. each time I get to > February of a leap year my program stops, Does it throw an exception (if so, post the traceback) or does it just terminat

Re: [Tutor] Help with class in class

2012-09-09 Thread Peter Otten
leam hall wrote: > I'm in the O'Reilly Python 2 class, so pointers to learning would be > better than just answers, please. My brain is a bit slow but needs to go > forward. > > Line 16 calls line 31. Rather, it is supposed to. I'm trying to figure out > why I get > > File "./ch8_project.py",

Re: [Tutor] index of elements in numpy array

2012-09-14 Thread Peter Otten
Bala subramanian wrote: > Thank you all for the answer. Below, i have pasted a sample code that > shows what i am intending to do. The code fails at line 13 as numpy > array dnt have a index attribute. > > 1 #!/usr/bin/env python > 2 import numpy as np > 3 > 4 a=np.array([1,2,3,4,5,6,7,8,

Re: [Tutor] (2.7.3) Inexplicable change of type

2012-09-14 Thread Peter Otten
Ray Jones wrote: > source = source.remove('') list.remove() modifies the list in-place and therefore by convention returns None: >>> source = ["one", "", "three"] >>> source.remove("") >>> source ['one', 'three'] ___ Tutor maillist - Tutor

Re: [Tutor] All possible 16 character alphanumeric strings?

2012-09-15 Thread Peter Otten
Scurvy Scott wrote: > Hello again python tutor list. > I have what I see as a somewhat complicated problem which I have no idea > where to begin. I'm hoping you fine folks can help me. > > I'm trying to generate a list of every possible 16 character string > containing only 2-7 and a-z lowercase.

Re: [Tutor] How to run this block of code dozens of times

2012-09-16 Thread Peter Otten
Scurvy Scott wrote: > Actually the loop would run 2^80 times Remember the previous thread? This means the loop will not terminate in the next few million years. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: htt

Re: [Tutor] Convert from meters to British length units.

2012-09-17 Thread Peter Otten
Johny Rei wrote: > Help out there folks,,.I'm completely lost on how to make a program where > you set a length given in meters and then compute and write out the > corresponding length measured in inches,in feet, in yards, and in > miles.Can anybody guide me here, By the example you may provide

Re: [Tutor] Convert from meters to British length units.

2012-09-17 Thread Peter Otten
Johny Rei wrote: [Please hit replay-all when you answer posts on this mailing list; that way everyone on the list can see your post] > Yes Sir, thank you sir, You're welcome. Note that we're OK with a less formal tone over here ;) > I do understand how this works, these is the printf formatt

Re: [Tutor] Border width of Canvas widget in tkinter

2012-09-19 Thread Peter Otten
Alok Joshi wrote: > I am using Python 3.x > > I am unable to remove the border in a Canvas widget with bd=0 or > borderwidth=0. Can someone please explain how one can do this? > > I give below my program > > class Avatar(Frame): > def > __init__(self,parent=None,width=100,height=100,ovalness=1

Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-19 Thread Peter Otten
Gregory Lund wrote: > I teach at a college and I'm trying to use Python (2.6 because I'm > running my tool in ArcGIS) to unzip a .zip file that contains one > folder full of student folders, each with 1 or more submissions > (zipfiles) that represent student submissions to weekly lab > assignments

Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-19 Thread Peter Otten
Gregory Lund wrote: >> Using Peter's code, if you create a plain text file called >> "unzip_twice.py" containing: >> >> >> import glob >> import os >> import sys >> import zipfile >> >> source_file = sys.argv[1] >> dest_folder = sys.argv[2] >> >> zipfile.ZipFile(source_file).extractall(dest_folder

Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-19 Thread Peter Otten
Steven D'Aprano wrote: > That's what we're here for! Don't be shy about asking questions. Indeed. Also, Gregory, don't expect anything to work directly. Programming is mostly an iterative process where you write just a little bit of code before you have to stop to fix a host of bugs. Repeat unt

Re: [Tutor] "bisect" vs "in"

2012-09-20 Thread Peter Otten
Albert-Jan Roskam wrote: > I want to repeatedly search a list to test whether that list contains a > given element X. Of course, I can use membership testing using "in" > (list._contains__). But how is this method implemented? It seems to just > walk through the whole list from beginning to end (s

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread Peter Otten
Ara Kooser wrote: > Morning, > > I dug out some old code from 5 years ago to clean up and get in working > order. It's a simple agent based model. I have class called Ant which > contains all the ant-like functions. > > I have a list that tracks the ants but I did this is a very crude way. I >

Re: [Tutor] application whitelisting

2012-09-21 Thread Peter Otten
Albert-Jan Roskam wrote: > Hi, > > My company just started application whitelisting. Now a new version of a > (benign!!) dll does not work as it (or rather, its file hash, if I > understood it correctly) is not whitelisted. Is there any way I can use > the same dll of a newer version? I know this

Re: [Tutor] Question about lists

2012-09-21 Thread Peter Otten
Leo Degon wrote: > I'm trying to create a class where the main focus is creating a list whose > elements are lists and the elements of those lists are collection of zeros > and ones. I am trying to create functions to rotate the list ninety > degrees, to reflect it. Having a few problems with the

Re: [Tutor] Relative import help

2012-09-22 Thread Peter Otten
Matthew Ngaha wrote: > i have an assignment from a book to practice implementing relative > imports. it gave a very clear and easy to follow explanation, but my > results are proving the instructions are wrong. here's what i have > tried. my folder structure: > > Project / > >__init__.py >

Re: [Tutor] Relative import help

2012-09-22 Thread Peter Otten
Matthew Ngaha wrote: >> You probably have a path that reaches into Domestic or Europe >> sub-package. That can happen if e. g. Project/Domestic/Europe is your >> current working directory. >> >> Try to cd into the Project folder's parent directory and see if >> >> $ python -c 'import Project.Domes

Re: [Tutor] Borg di borg di borg (or: Swedish chef)

2012-09-24 Thread Peter Otten
Albert-Jan Roskam wrote: > Hi Pythonistas, > > I have three classes, Generic, Test and Test2. Generic contains a load > method that loads a file. This may only be done once, as a file_read_open > error is returned if the file is open already and an attempt is made to > re-open it. The file may be

Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-25 Thread Peter Otten
Gregory Lund wrote: > if item.endswith('.zip'): > # Combine the base folder name with the subpath to the zip file > fullpath = os.path.join(outDir, item) > x = zipfile.ZipFile(fullpath,'a') Why did you change file mode to "a"? > x.extractall() > x.clos

Re: [Tutor] lazily decorated sort

2012-09-28 Thread Peter Otten
Chris Smith wrote: > I'm wondering if anyone has seen or knows of a good way to do a lazily > decorated sort. I was reading about how good the DSU (decorate, sort, > undecorate) approach is but the problem that we are running into in > SymPy is that we want to get by with a fast hash sort if possi

Re: [Tutor] lazily decorated sort

2012-09-28 Thread Peter Otten
eryksun wrote: > On Fri, Sep 28, 2012 at 8:17 AM, Peter Otten <__pete...@web.de> wrote: >> >> def make_key(keys): >> @total_ordering >> class Key(object): >> def __init__(self, value): >> self._keys = keys(value) >

Re: [Tutor] a question about maxint

2012-10-02 Thread Peter Otten
Katya Stolpovskaya wrote: > I have this error: > from sys import * maxint > Traceback (most recent call last): > File "", line 1, in > maxint > NameError: name 'maxint' is not defined > > > What does it mean and how to deal with it? You are probably using Python 3 which doesn't have

Re: [Tutor] ctypes question

2012-10-10 Thread Peter Otten
Albert-Jan Roskam wrote: > I have a program that reads and writes files using ctypes. When I want it > to read AND write (e.g. read a file, select some stuff and write that), > the library returns a 'read-open' error. I think that the pointer to the > file handle for read and write point to the sa

Re: [Tutor] map() practice

2012-10-21 Thread Peter Otten
Malcolm Newsome wrote: > Hello all, > > I looked at map() tonight. I think I have a decent understanding now of > "how" it works. However, I'm wondering when it is most commonly used in > the real world and if you could provide some examples (I like to do a > lot of web stuff...it that helps wi

<    1   2   3   4   5   6   7   8   9   10   >