Re: What is the Most Efficient Way of Printing A Dict's Contents Out In Columns?

2011-06-14 Thread MRAB
On 14/06/2011 18:48, Zach Dziura wrote: [snip] I just have one quick question. On the line where you have zip(*arr), what is the * for? Is it like the pointer operator, such as with C? Or is it exactly the pointer operator? [snip] The * in the argument list of a function call unpacks the follow

Re: working with raw image files

2011-06-14 Thread MRAB
On 14/06/2011 21:13, kafooster wrote: Ok, I solved the problem with matplotlib fileobj = open("hand.raw", 'rb') data = numpy.fromfile(fileobj,dtype=np.uint16) data = numpy.reshape(data,(96,470,352)) imshow(data[:,:,40],cmap='gray') show() the error was caused by different order of data, however

Re: working with raw image files

2011-06-14 Thread MRAB
On 14/06/2011 22:20, kafooster wrote: On 14 Cze, 22:26, MRAB wrote: Multiply the numpy array by a scaling factor, which is float(max_8bit_value) / float(max_16bit_value). could you please explain it a little? I dont understand it. like multiplying each element? Yes. Something like this

Re: break in a module

2011-06-14 Thread MRAB
On 14/06/2011 23:28, Eric Snow wrote: [snip] With modules I sometimes have code at the beginning to do some small task if a certain condition is met, and otherwise execute the rest of the module body. Here's my main use case: """some module""" import sys import importlib import uti

Re: working with raw image files

2011-06-14 Thread MRAB
On 15/06/2011 00:59, kafooster wrote: On 15 Cze, 00:06, MRAB wrote: Yes. Something like this: fileobj = open("hand.raw", 'rb') data = numpy.fromfile(fileobj, dtype=numpy.uint16) fileobj.close() data = data * float(0xFF) / float(0x) data = numpy.array(data, dty

Re: bug in large file writes, 2.x and 3.x

2011-06-17 Thread MRAB
On 17/06/2011 20:15, Ethan Furman wrote: Ethan Furman wrote: Windows platform (XP Pro, SP2). This works fine on local drives, but on network (both 2003 Server, and Samba running on FreeBSD) the following produces an error: --> data = '?' * 119757831 # use b'?' if on 3.x --> test = open(r's:\ju

Re: Boolean result of divmod

2011-06-20 Thread MRAB
On 21/06/2011 01:28, Gnarlodious wrote: What is the easiest way to get the first number as boolean? divmod(99.6, 30.1) Or do I have to say: flote, rem=divmod(99.6, 30.1) bool(flote) divmod returns a tuple, so: bool(divmod(99.6, 30.1)[0]) -- http://mail.python.org/mailman/listinfo/python

Re: How to iterate on a changing dictionary

2011-06-21 Thread MRAB
On 21/06/2011 12:51, Gurpreet Singh wrote: Perhaps this is the simplest and best solution which appears in this case. Just copy the desired items to a new dictionary and discard the original one. import re myDict={'a':'alpha','b':'beta','c':'charley','d':'disney'} myNewDict={} for k,v in myDict

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread MRAB
On 21/06/2011 20:48, John Salerno wrote: I'm working on the Project Euler exercises and I'm stumped on problem 3: "What is the largest prime factor of the number 600851475143 ?" Now, I've actually written functions to get a list of the factors of any given number, and then another function to g

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread MRAB
On 22/06/2011 02:21, John Salerno wrote: ::sigh:: Well, I'm stuck again and it has to do with my get_factors function again, I think. Even with the slight optimization, it's taking forever on 20! (factorial, not excitement) :) It's frustrating because I have the Python right, but I'm getting stu

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-22 Thread MRAB
On 22/06/2011 06:58, Chris Torek wrote: Now that the exercise has been solved... Instead of "really short code to solve the problem", how about some "really long code"? :-) I was curious about implementing prime factorization as a generator, using a prime-number generator to come up with the fa

Re: writable iterators?

2011-06-22 Thread MRAB
On 23/06/2011 00:10, Neal Becker wrote: Steven D'Aprano wrote: On Wed, 22 Jun 2011 15:28:23 -0400, Neal Becker wrote: AFAICT, the python iterator concept only supports readable iterators, not write. Is this true? for example: for e in sequence: do something that reads e e = blah # wil

Re: How to run a function in SPE on Python 2.5

2011-06-22 Thread MRAB
On 23/06/2011 03:19, bill lawhorn wrote: I have a program: decrypt2.py which contains this function: def scramble2Decrypt(cipherText): halfLength = len(cipherText) // 2 oddChars = cipherText[:halfLength] evenChars = cipherText[halfLength:] plainText = "" for i in range

Re: how to call a function for evry 10 secs

2011-06-30 Thread MRAB
On 30/06/2011 17:42, Dennis Lee Bieber wrote: On Thu, 30 Jun 2011 10:37:34 +0200, Ulrich Eckhardt declaimed the following in gmane.comp.python.general: "time.sleep()" takes a floating point number, so an underflow like for fixed-size integers in C shouldn't happen. What puzzles me here is you

Re: text file

2011-06-30 Thread MRAB
On 01/07/2011 01:19, Siboniso Shangase wrote: Hi i m very new to python and i need hepl plz!! i want to type this data in a text file it the same the diffrence is the number that only increase and i canot write this up myself since it up to 5000 samples Data\ja1.wav Data\ja1.mfc Data\ja2.wav Da

Re: Why won't this decorator work?

2011-07-02 Thread MRAB
On 02/07/2011 17:56, John Salerno wrote: I thought I had finally grasped decorators, but the error I'm getting ('str' type is not callable) is confusing me. Here is my code. Also, the commented sentence is from the Python docs, which says it doesn't even need to be callable, if that matters. I al

Re: [Python-ideas] Allow isinstance second argument to be a set of types

2011-07-04 Thread MRAB
On 04/07/2011 20:41, Amaury Forgeot d'Arc wrote: Hi, 2011/7/4 Antoine Pitrou: Le lundi 04 juillet 2011 à 10:52 -0700, Gregory P. Smith a écrit : note that a fast lookup implies exact type and not subclass making my point silly... at which point you're back to iterating so I suspect supporting

Re: Implicit initialization is EVIL!

2011-07-06 Thread MRAB
On 06/07/2011 20:15, Ian Kelly wrote: On Wed, Jul 6, 2011 at 12:36 PM, Andrew Berg wrote: On 2011.07.06 01:19 PM, rantingrick wrote: ## The Roman Stawman Sketch ## Nice try, but you have to use a Monty Python sketch (and you have to spell corr

Re: i get different answers based on run platform

2011-07-07 Thread MRAB
On 07/07/2011 19:18, linda wrote: I have this simple palindrome program that yields different results depending on whether I run it from Windows or from IDLE. The answer is correct off IDLE, but why is this the case? Here's the code: def reverse(text): return text[::-1] def is_palindrome(

Re: i get different answers based on run platform

2011-07-07 Thread MRAB
On 07/07/2011 19:37, John Gordon wrote: In<842fce9d-1b3f-434a-b748-a6dc4828c...@h12g2000pro.googlegroups.com> linda writes: I have this simple palindrome program that yields different results depending on whether I run it from Windows or from IDLE. The answer is correct off IDLE, but why is

Re: I don't know list, I not good at list.

2011-07-13 Thread MRAB
> I've been beating my head against the desk trying to figure out a > method to accomplish this: > > Take a list (this example is 5 items, It could be 150 or more - i.e. > it's variable length depending on the city/local calling zones) > > The first 6 digits of phone numbers(NPA/NXX) in a local ca

Re: PyCon Australia 2011: Schedule Announced

2011-07-13 Thread MRAB
On 14/07/2011 00:24, Ryan Kelly wrote: [snip] Ah! I see you have the machine that goes "BING"! (Graeme Cross) Surely it goes "PING"! -- http://mail.python.org/mailman/listinfo/python-list

Re: should i install python image library by myself?

2011-07-13 Thread MRAB
On 14/07/2011 01:18, think wrote: when i type import image in the python interactive command, i am surprised to find that it does not work. the details are as follows: >>> import image Traceback (most recent call last): File "", line 1, in ? ImportError: No module named image i wonder the image

Re: Please critique my script

2011-07-14 Thread MRAB
[snip] raw_input() returns a string, so there's no need for these 3 lines: > y = str(y) > z = str(z) > p = str(p) > pagedef = ("http://www.localcallingguide.com/xmllocalprefix.php?npa="; + y + "&nxx=" + z) > print "Querying", pagedef > > #--Get info from NANPA.com -- > urllib2.inst

Re: json decode issue

2011-07-14 Thread MRAB
On 14/07/2011 18:22, Miki Tebeka wrote: Greetings, I'm trying to decode JSON output of a Java program (jackson) and having some issues. The cause of the problem is the following snippet: { "description": "... lives\uMOVE™ OFFERS ", } Which causes ValueError: Invalid \u es

Re: Please critique my script

2011-07-14 Thread MRAB
On 14/07/2011 21:53, Peter Otten wrote: MRAB wrote: for line2 in nxxReg.findall(soup): nxxlist.insert(count2, line2) count2 = count2 + 1 enumerate will help you here: for count2, line2 in enumerate(nxxReg.findall(soup)): nxxlist.insert(count2, line2) An insert() at the

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-18 Thread MRAB
On 18/07/2011 14:52, Duncan Booth wrote: Tim Chase wrote: On 07/17/2011 08:01 PM, Steven D'Aprano wrote: Roy Smith wrote: We don't have that problem any more. It truly boggles my mind that we're still churning out people with 80 column minds. I'm willing to entertain arguments about readab

Re: a little parsing challenge ☺

2011-07-18 Thread MRAB
On 19/07/2011 03:07, Billy Mays wrote: On 7/18/2011 7:56 PM, Steven D'Aprano wrote: Billy Mays wrote: On 07/17/2011 03:47 AM, Xah Lee wrote: 2011-07-16 I gave it a shot. It doesn't do any of the Unicode delims, because let's face it, Unicode is for goobers. Goobers... that would be one of

Re: regex question

2011-07-29 Thread MRAB
On 29/07/2011 16:45, Thomas Jollans wrote: On 29/07/11 16:53, rusi wrote: Can someone throw some light on this anomalous behavior? import re r = re.search('a(b+)', 'ababbaaab') r.group(1) 'b' r.group(0) 'ab' r.group(2) Traceback (most recent call last): File "", line 1, in IndexErr

Re: How to define repeated string when using the re module?

2011-08-02 Thread MRAB
On 02/08/2011 17:20, smith jack wrote: if it's for a single character, this should be very easy, such as c{m,n} the occurrence of c is between m and n, if i want to define the occurrence of (.*?) how should make it done? ((.*?)){1,3} seems not work, any method to define repeat string using

Re: problem with bcd and a number

2011-08-04 Thread MRAB
On 04/08/2011 19:26, nephish wrote: Hey all, I have been trying to get my head around how to do something, but i am missing how to pull it off. I am reading a packet from a radio over a serial port. i have " two bytes containing the value i need. The first byte is the LSB, second is MSB. Both

Re: Network shares in Windows

2011-08-08 Thread MRAB
On 09/08/2011 02:46, Nanda, Ameet wrote: Hi All, I was trying to access a network shared folder on a windows network. I couldn’ t find of a good documentation online to do that. Are there any recommendations on how to do it in windows. So if my folder is shared as \\ameetn\Dropbox and when I am

Re: Directions on accessing shared folder in windows network

2011-08-10 Thread MRAB
On 10/08/2011 20:52, Ameet Nanda wrote: Hi, Can anyone point me to a way to access windows shared folders from the network using a python script. I tried accessing using open, which is mentioned to work perfectly on the web, but it gives me following errors >>>open(NW_PATH) it gives me a perm

Re: Bizarre behavior of the 'find' method of strings

2011-08-10 Thread MRAB
On 11/08/2011 02:24, Jim wrote: Greetings, folks, I am using python 2.7.2. Here is something I got: a = 'popular' i = a.find('o') j = a.find('a') a[i:j] 'opul' Well, I expected a[i:j] to be 'opula', and can't think of any reason why this is not happening. So, can anybody help me out about thi

Re: allow line break at operators

2011-08-11 Thread MRAB
On 11/08/2011 05:16, Chris Rebert wrote: On Wed, Aug 10, 2011 at 7:52 PM, Yingjie Lan wrote: :And if we require {} then truly free indentation should be OK too! But :it wouldn't be Python any more. Of course, but not the case with ';'. Currently ';' is optional in Python, I think of it more

Re: indentation

2011-08-11 Thread MRAB
On 11/08/2011 13:56, Amit Jaluf wrote: Hello Group, i just start python is it necessary indentation in python ? Yes, indentation is part of the language. Even in programming languages where it isn't necessary, it's recommended because it makes the code easier to read. -- http://mail.python.org

Re: TypeError: 'module' object is not callable

2011-08-11 Thread MRAB
On 11/08/2011 23:43, Forafo San wrote: I wrote a class, Univariate, that resides in a directory that is in my PYTHONPATH. I'm able to import that class into a *.py file. However when I try to instantiate an object with that class like: x = Univariate(a) # a is a list that is expect

Re: Processing a large string

2011-08-11 Thread MRAB
On 12/08/2011 03:03, goldtech wrote: Hi, Say I have a very big string with a pattern like: akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn. I want to split the sting into separate parts on the "3" and process each part separately. I might run into memory limitations if I use "split"

Re: Java is killing me! (AKA: Java for Pythonheads?)

2011-08-12 Thread MRAB
On 12/08/2011 18:02, kj wrote: *Please* forgive me for asking a Java question in a Python forum. My only excuse for this no-no is that a Python forum is more likely than a Java one to have among its readers those who have had to deal with the same problems I'm wrestling with. Due to my job, I

Re: Ten rules to becoming a Python community member.

2011-08-15 Thread MRAB
On 15/08/2011 17:18, Lucio Santi wrote: On Mon, Aug 15, 2011 at 9:06 AM, Neil Cerutti mailto:ne...@norwich.edu>> wrote: On 2011-08-14, Chris Angelico mailto:ros...@gmail.com>> wrote: > On Sun, Aug 14, 2011 at 2:21 PM, Irmen de Jong mailto:irmen.nos...@xs4all.nl>> wrote: >> On

Re: Ten rules to becoming a Python community member.

2011-08-15 Thread MRAB
On 16/08/2011 01:52, Gregory Ewing wrote: I don't mind people using e.g. and i.e. as long as they use them *correctly*. Many times people use i.e. when they really mean e.g. Can you give me an example? :-) -- http://mail.python.org/mailman/listinfo/python-list

Re: testing if a list contains a sublist

2011-08-16 Thread MRAB
On 16/08/2011 00:26, Johannes wrote: hi list, what is the best way to check if a given list (lets call it l1) is totally contained in a second list (l2)? for example: l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 l1 = [1,2,3]

Re: Ten rules to becoming a Python community member.

2011-08-16 Thread MRAB
On 16/08/2011 19:37, Martin P. Hellwig wrote: On 16/08/2011 18:51, Prasad, Ramit wrote: Incorrect past tense usage of "used to": """ I "used to" wear wooden shoes """ Incorrect description using "used to": """ I have become "used to" wearing wooden shoes """ Correct usage of "used to": """

Re: Syntactic sugar for assignment statements: one value to multiple targets?

2011-08-16 Thread MRAB
On 17/08/2011 01:14, gc wrote: On Aug 16, 4:39 pm, "Martin P. Hellwig" wrote: On 03/08/2011 02:45, gc wrote: a,b,c,d,e = *dict() where * in this context means something like "assign separately to all. . . . it has a certain code smell to it. I would love to see an example where you wo

Re: Syntactic sugar for assignment statements: one value to multiple targets?

2011-08-17 Thread MRAB
On 17/08/2011 10:26, gc wrote: On Aug 17, 3:13 am, Chris Angelico wrote: Minor clarification: You don't want to initialize them to the same value, which you can do already: a=b=c=d=e=dict() Right. Call the proposed syntax the "instantiate separately for each target" operator. (It can be pr

Re: Help with regular expression in python

2011-08-19 Thread MRAB
On 19/08/2011 20:55, ru...@yahoo.com wrote: On 08/19/2011 11:33 AM, Matt Funk wrote: On Friday, August 19, 2011, Alain Ketterlin wrote: Matt Funk writes: thanks for the suggestion. I guess i had found another way around the problem as well. But i really wanted to match the line exactly and i

Re: Run time default arguments

2011-08-25 Thread MRAB
On 25/08/2011 15:30, t...@thsu.org wrote: What is the most common way to handle default function arguments that are set at run time, rather than at compile time? The snippet below is the current technique that I've been using, but it seems inelegant. defaults = { 'debug' : false } def doSomethin

Re: Arrange files according to a text file

2011-08-27 Thread MRAB
On 27/08/2011 18:03, r...@rdo.python.org wrote: Hello, What would be the best way to accomplish this task? I have many files in separate directories, each file name contain a persons name but never in the same spot. I need to find that name which is listed in a large text file in the following f

Re: Arrange files according to a text file

2011-08-27 Thread MRAB
On 28/08/2011 00:18, r...@rdo.python.org wrote: Thank you so much. The code worked perfectly. This is what I tried using Emile code. The only time when it picked wrong name from the list was when the file was named like this. Data Mark Stone.doc How can I fix this? Hope I am not asking too muc

Re: On re / regex replacement

2011-08-28 Thread MRAB
default and "corrected" via the NEW flag (e.g. zero-width split). Also the LOCALE flag seems to be considered as legacy feature and kept with the same behaviour like re; cf.: http://code.google.com/p/mrab-regex-hg/issues/detail?id=6&can=1 In my opinon, the LOCALE flag is not reliable (in

Re: killing a script

2011-08-28 Thread MRAB
On 29/08/2011 02:15, Russ P. wrote: I have a Python (2.6.x) script on Linux that loops through many directories and does processing for each. That processing includes several "os.system" calls for each directory (some to other Python scripts, others to bash scripts). Occasionally something goes

Re: Usage of PyDateTime_FromTimestamp

2011-08-30 Thread MRAB
On 30/08/2011 21:42, Andreas wrote: Hi, I'm working on a c-extension of python and want to create an instance of python datetime object with a unix timestamp in c. On the documentation site ( http://docs.python.org/c-api/datetime.html ) I found the function PyDateTime_FromTimestamp() which retu

Re: Usage of PyDateTime_FromTimestamp

2011-08-31 Thread MRAB
On 31/08/2011 04:39, Andreas wrote: Am 30.08.2011 23:49, schrieb MRAB: The key phrase is "argument tuple". The arguments passed to a Python call are always a tuple, not PyFloat_Object. You can build a tuple from the PyFloat_Object using: Py_BuildValue("(O)", fl

Re: List comprehension timing difference.

2011-09-01 Thread MRAB
On 02/09/2011 01:35, Bart Kastermans wrote: In the following code I create the graph with vertices sgb-words.txt (the file of 5 letter words from the stanford graphbase), and an edge if two words differ by one letter. The two methods I wrote seem to me to likely perform the same computations, t

Re: Functions vs OOP

2011-09-03 Thread MRAB
On 03/09/2011 17:15, William Gill wrote: During some recent research, and re-familiarization with Python, I came across documentation that suggests that programming using functions, and programming using objects were somehow opposing techniques. It seems to me that they are complimentary. I th

Re: Reading pen drive data

2011-09-03 Thread MRAB
On 03/09/2011 17:21, mukesh tiwari wrote: On Sep 3, 7:40 pm, mukesh tiwari wrote: Hello all I am trying to write a python script which can mount a pen drive and read the data from pen drive. I am using pyudev [http://packages.python.org/pyudev/api/index.html] and wrote a small python code imp

Re: [Python-ideas] allow line break at operators

2011-09-03 Thread MRAB
On 04/09/2011 00:22, Yingjie Lan wrote: Every language with blocks needs some mechanism to indicate the beginning and ending of blocks and of statements within blocks. If visible fences ('begin/end' or '{}') and statement terminators (';') are used, then '\n' can be treated as merely a space, a

Re: MIMEText encode error - Python 2.6.6

2011-09-06 Thread MRAB
On 06/09/2011 22:52, neubyr wrote: I am trying to write a program which can email file's content using smtplib. I am getting following error while using Python 2.6.6 version. {{{ File "./killed_jobs.py", line 88, in sendmail msg = MIMEText(ipfile.read, 'plain') File "/home/ssp/sge/python/2

Re: PEP 20 - Silly Question?

2011-09-06 Thread MRAB
On 07/09/2011 01:36, Ben Finney wrote: Zero Piraeus writes: On 6 September 2011 12:17, Joseph Armbruster wrote: I noticed that it says only 19 of 20 have been written down. Which one was not written down? The last one. I always thought it was the first one. Or the 6.25th one, I forget.

Re: I am confused by

2011-09-07 Thread MRAB
On 07/09/2011 23:57, Martin Rixham wrote: Hi all I would appreciate some help understanding something. Basically I am confused by the following: >>> a = [[0, 0], [0, 0]] >>> b = list(a) >>> b[0][0] = 1 >>> a [[1, 0], [0, 0]] I expected the last line to be [[0, 0], [0, 0]] I hope that's cl

Re: Python C Extensions

2011-02-24 Thread MRAB
On 24/02/2011 16:01, aken8...@yahoo.com wrote: Hi, I have a memory leak problem with my "C" extension module. My C module returns large dictionaries to python, and the dictionaries never get deleted, so the memory for my program keeps growing. I do not know how to delete the dictionary object a

Re: Python C Extensions

2011-02-24 Thread MRAB
On 24/02/2011 16:46, aken8...@yahoo.com wrote: Thank you very much, it worked. I thought the PyDict_SetItem should assume ownership of the passed object and decrease it's reference count (I do not know why). Does this also go for the Lists ? Should anything inserted into list also be DECRED-ed ?

Re: n00b formatting

2011-02-24 Thread MRAB
On 24/02/2011 16:41, Verde Denim wrote: hi, all i can't believe i don't see this, but python from the command line: >>> x = '0D' >>> y = '0x' + x >>> print "%d" % int(y,0) 13 content of testme.py: x = '0D' y = '0x' + x print "%d" % int(y,0) TypeError: 'int' object is not callable what am i n

Re: py3k: datetime resolution / isoformat

2011-02-25 Thread MRAB
On 26/02/2011 02:21, s...@uce.gov wrote: When I do: datetime.datetime.now().isoformat(' ') I get the time with the microseconds. The docs says: "if microsecond is 0 -MM-DDTHH:MM:SS+HH:MM". How do I set microsecond to 0? >>> datetime.datetime.microsecond = 0 Traceback (most recent call l

Re: nntplib encoding problem

2011-02-27 Thread MRAB
On 28/02/2011 01:31, Laurent Duchesne wrote: Hi, I'm using python 3.2 and got the following error: nntpClient = nntplib.NNTP_SSL(...) nntpClient.group("alt.binaries.cd.lossless") nntpClient.over((534157,534157)) ... 'subject': 'Myl\udce8ne Farmer - Anamorphosee (Japan Edition) 1995 [02/41] "B

Re: Lumberjack Song

2011-02-28 Thread MRAB
On 28/02/2011 10:26, Tom Zych wrote: We all like computers here. No doubt many of us like computer games. And most of us will be at least somewhat familiar with Monty Python. Therefore, I present (drum roll)... http://www.youtube.com/watch?v=Zh-zL-rhUuU (For the Runescape fans out there, this s

Re: Strange occasional marshal error

2011-03-03 Thread MRAB
On 03/03/2011 15:09, Graham Stratton wrote: On Mar 2, 3:01 pm, Graham Stratton wrote: We are using marshal for serialising objects before distributing them around the cluster, and extremely occasionally a corrupted marshal is produced. The current workaround is to serialise everything twice and

Re: help with regex matching multiple %e

2011-03-03 Thread MRAB
On 03/03/2011 17:33, maf...@nmsu.edu wrote: Hi, i have a line that looks something like: 2.234e+04 3.456e+02 7.234e+07 1.543e+04: some description I would like to extract all the numbers. From the python website i got the following expression for matching what in c is %e (i.e. scientific format

Re: subprocess running ant

2011-03-03 Thread MRAB
On 03/03/2011 18:14, Thom Hehl wrote: I am attempting to write a python script that will check out and build our code, then deploy the executable. It will report any failures via e-mail. To this end, I’m trying to run my ant build from inside of python. I have tried the following: proc = subpro

Re: making a class callable

2011-03-03 Thread MRAB
On 04/03/2011 01:45, dude wrote: I've been struggling with getting my class to behave the way I want it. I have python module called ohYeah.py, defined as follows... #File Begin class foo: def __init__(self, arg1): print arg1 self.ohYeah = arg1 def whatwhat(self):

Re: how to read the last line of a huge file???

2011-03-04 Thread MRAB
On 04/03/2011 21:46, tkp...@hotmail.com wrote: I've implementing this method of reading a file from the end, i.e def seeker(filename): offset = -10 with open(filename) as f: while True: f.seek(offset, os.SEEK_END) lines = f.readlines() if

Re: my computer is allergic to pickles

2011-03-04 Thread MRAB
On 05/03/2011 01:56, Bob Fnord wrote: I'm using python to do some log file analysis and I need to store on disk a very large dict with tuples of strings as keys and lists of strings and numbers as values. I started by using cPickle to save the instance of the class that contained this dict, but

Re: having both dynamic and static variables

2011-03-05 Thread MRAB
On 06/03/2011 02:37, John Nagle wrote: On 3/2/2011 9:27 PM, Steven D'Aprano wrote: On Wed, 02 Mar 2011 19:45:16 -0800, Yingjie Lan wrote: Hi everyone, Variables in Python are resolved dynamically at runtime, which comes at a performance cost. However, a lot of times we don't need that feature

Re: re documentation bug?

2011-03-07 Thread MRAB
On 08/03/2011 03:01, Tycho Andersen wrote: Consider the following session: Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. import re p = re.compile("foo") re.sub(p, "bar", "foobaz", flags=re.IGNORECASE

Re: Dijkstra Algorithm Help

2011-03-08 Thread MRAB
On 08/03/2011 18:12, yoro wrote: Hello, I am having a little trouble writing Dijkstra's Algorithm, at the point where I have to calculate the distance of each node from the source - here is my code so far: infinity = 100 invalid_node = -1 startNode = 0 class Node: distFromSource = in

Re: error in exception syntax

2011-03-09 Thread MRAB
On 09/03/2011 18:12, Aaron Gray wrote: On Windows I have installed Python 3.2 and PyOpenGL-3.0.1 and am getting the following error :- File "c:\Python32\lib\site-packages\OpenGL\platform\win32.py", line 13 except OSError, err: ^ It works okay on my Linux machine running Python 2.6.2. Many than

Re: Tcl wasn't installed properly

2011-03-10 Thread MRAB
On 10/03/2011 15:39, Steve wrote: I'm a frequent user of matplotlib on my Windows XP machine. I recently attempted to install a program that modified my Tcl installation, and I now get an error message when I attempt to plot anything in matplotlib. Here is the error message: --- Traceback (most

Re: Tk MouseWheel Support

2011-03-10 Thread MRAB
On 10/03/2011 20:28, Richard Holmes wrote: I am trying to use the mouse wheel to scroll a list box, but I'm not getting the event. When I bind "" to the listbox I get the event and I'm able to scroll using yview_scroll. I've tried binding "MouseWheel" and"", and I've also tried"" and "" even thou

Re: send function keys to a legacy DOS program

2011-03-10 Thread MRAB
On 11/03/2011 00:58, Justin Ezequiel wrote: Greetings, We have an old barcode program (MSDOS and source code unavailable.) I've figured out how to populate the fields (by hacking into one of the program's resource files.) However, we still need to hit the following function keys in sequence. F5,

Re: Passing Functions

2011-03-10 Thread MRAB
On 11/03/2011 01:13, yoro wrote: Hi, I am having an issue with passing values from one function to another - I am trying to fill a list in one function using the values contained in other functions as seen below: infinity = 100 invalid_node = -1 startNode = 0 #Values to assign to each node

Re: Just finished reading of "What’s New In Python 3.0"

2011-03-10 Thread MRAB
On 11/03/2011 02:05, alex23 wrote: On Mar 11, 11:58 am, n00m wrote: http://docs.python.org/py3k/whatsnew/3.0.html What's the fuss abt it? Imo all is ***OK*** with 3k (in the parts I understand). I even liked print as a function **more** than print as a stmt Now I think that Py3k is better tha

Re: Inserting record into postgresql database

2011-03-11 Thread MRAB
On 11/03/2011 22:08, Meszaros, Stacy wrote: Hello all, I am using python 2.6 and the psycopg2 module for the postgres connection The following code is supposed to insert a record into a table with a bytea field. (bytearray) I am having difficulty getting to field inserted properly. The snippet

Re: How should I handle socket receiving?

2011-03-14 Thread MRAB
On 14/03/2011 19:47, Hans wrote: On Mar 12, 10:13 pm, Tim Roberts wrote: Hans wrote: I'm thinking to write a code which to: 1. establish tons of udp/tcp connections to a server What does "tons" mean? Tens? Hundreds? my question is how should I handle receiving traffic from each connect

Re: using simplejson.dumps to encode a dictionary to json

2011-03-15 Thread MRAB
On 15/03/2011 19:40, Aaron wrote: Hi there, I am attempting to use simplejson.dumps to convert a dictionary to a json encoded string. For some reason this doesn't work - it would be awesome if someone could give me a clue as to why. loginreq = {"username":username, "password":password, "prod

Re: using simplejson.dumps to encode a dictionary to json

2011-03-15 Thread MRAB
On 15/03/2011 19:56, Aaron wrote: If I print authreq_data to screen I get {"req": {"username": "##", "password": "#", "productType": "CFD_Demo"}} Essentially I want the inner brackets to be [ ] instead of {} but alternating on each level so it would be: {"req": [{"username": "##

Re: Multiprocessing.Process Daemonic Behavior

2011-03-15 Thread MRAB
On 16/03/2011 02:34, John L. Stephens wrote: Greetings, I'm trying to understand the behavior of the multiprocessing.Process daemonic attribute. Based on what I have read, if a Process ( X ) is created, and before it is started ( X.start() ), I should be able to set the process as daemonic usin

Re: class error

2011-03-18 Thread MRAB
On 18/03/2011 20:13, monkeys paw wrote: I have the following file: FileInfo.py: import UserDict class FileInfo(UserDict): "store file metadata" def __init__(self, filename=None): UserDict.__init__(self) self["name"] = filename When i import it like so: import FileIn

Re: puzzle about file Object.readlines()

2011-03-19 Thread MRAB
On 19/03/2011 13:15, 林桦 wrote: > i use python 2.5. os is window 7. > the puzzle is :python don't read the leave text when meet character: > chr(26) > the code is: > /fileObject=open('d:\\temp\\1.txt','w') > fileObject.write('22\r\n') > fileObject.write(chr(26)+'\r\n') > fileObject.writ

Re: python time

2011-03-20 Thread MRAB
On 21/03/2011 02:48, ecu_jon wrote: On Mar 20, 10:09 pm, Dave Angel wrote: On 01/-10/-28163 02:59 PM, ecu_jon wrote: I'm working on a script that will run all the time. at time specified in a config file, will kick-off a backup. problem is, its not actually starting the job. the double whil

Re: python time

2011-03-20 Thread MRAB
On 21/03/2011 03:29, ecu_jon wrote: On Mar 20, 10:48 pm, ecu_jon wrote: On Mar 20, 10:09 pm, Dave Angel wrote: On 01/-10/-28163 02:59 PM, ecu_jon wrote: I'm working on a script that will run all the time. at time specified in a config file, will kick-off a backup. problem is, its not ac

Re: file print extra spaces

2011-03-22 Thread MRAB
On 23/03/2011 01:33, monkeys paw wrote: When i open a file in python, and then print the contents line by line, the printout has an extra blank line between each printed line (shown below): >>> f=open('authors.py') >>> i=0 >>> for line in f: print(line) i=i+1 if i > 14: break author_list =

Re: file print extra spaces

2011-03-22 Thread MRAB
On 23/03/2011 01:54, Thomas L. Shinnick wrote: At 08:33 PM 3/22/2011, monkeys paw wrote: When i open a file in python, and then print the contents line by line, the printout has an extra blank line between each printed line (shown below): >>> f=open('authors.py') >>> i=0 >>> for line in f: prin

Re: Guido rethinking removal of cmp from sort method

2011-03-24 Thread MRAB
On 24/03/2011 23:49, Steven D'Aprano wrote: On Thu, 24 Mar 2011 17:47:05 +0100, Antoon Pardon wrote: However since that seems to be a problem for you I will be more detailed. The original poster didn't ask for cases in which cmp was necessary, he asked for cases in which not using cmp was cumbe

Re: embedding interactive python interpreter

2011-03-25 Thread MRAB
On 25/03/2011 17:37, Eric Frederich wrote: So I found that if I type ctrl-d then the other lines will print. It must be a bug then that the exit() function doesn't do the same thing. The documentation says "The return value will be the integer passed to the sys.exit() function" but clearly n

Re: [SPAM] FW: ciao

2011-03-26 Thread MRAB
On 26/03/2011 18:07, bledar seferi wrote: 3.Scrivere unafunsioncheprende comeargomentouna lista diinterierestituisce uninsieme contenentequei numerichesono2 o più voltenellalista fornita.Per esempio,seservecomelista di input=[1,2,3,3,4,4,5,6,7,7,7],quindila funzionerestituiràilse

Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread MRAB
On 29/03/2011 18:01, Dan Stromberg wrote: On Tue, Mar 29, 2011 at 1:46 AM, Antoon Pardon mailto:antoon.par...@rece.vub.ac.be>> wrote: The double sort is useless if the actual sorting is done in a different module/function/method than the module/function/method where the order is imp

Re: Guido rethinking removal of cmp from sort method

2011-03-29 Thread MRAB
On 29/03/2011 21:32, Dan Stromberg wrote: On Tue, Mar 29, 2011 at 12:48 PM, Ian Kelly mailto:ian.g.ke...@gmail.com>> wrote: On Tue, Mar 29, 2011 at 1:08 PM, Chris Angelico mailto:ros...@gmail.com>> wrote: > On Wed, Mar 30, 2011 at 5:57 AM, MRAB mailto:pyt...@mrab

Re: In List Query -> None Case Sensitive?

2011-03-31 Thread MRAB
On 31/03/2011 23:05, Ethan Furman wrote: Wehe, Marco wrote: I am doing a search through a list of files but the text the casing doesn't match. My list is all upper case but the real files are all different. Is there a smooth way of searching through the list without going full on regular express

Re: Extracting subsequences composed of the same character

2011-03-31 Thread MRAB
On 01/04/2011 01:43, candide wrote: Suppose you have a string, for instance "pyyythhooonnn ---> " and you search for the subquences composed of the same character, here you get : 'yyy', 'hh', 'ooo', 'nnn', '---', '' It's not difficult to write a Python code that solves the problem, fo

Re: Extracting "true" words

2011-04-01 Thread MRAB
On 01/04/2011 21:55, candide wrote: Back again with my study of regular expressions ;) There exists a special character allowing alphanumeric extraction, the special character \w (BTW, what the letter 'w' refers to?). But this feature doesn't permit to extract true words; by "true" I mean word co

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