Re: Printing n elements per line in a list

2006-08-16 Thread Matimus
unexpected wrote: > If have a list from 1 to 100, what's the easiest, most elegant way to > print them out, so that there are only n elements per line. > > So if n=5, the printed list would look like: > > 1 2 3 4 5 > 6 7 8 9 10 > 11 12 13 14 15 > etc. > > My search through the previous posts yields

Re: Printing n elements per line in a list

2006-08-16 Thread Matimus
John Machin wrote: > Matimus wrote: > > unexpected wrote: > > > If have a list from 1 to 100, what's the easiest, most elegant way to > > > print them out, so that there are only n elements per line. > > > > > > So if n=5, the printed list would

Re: how do you get the name of a dictionary?

2006-08-18 Thread Matimus
You could do something like this: >>> class MyDict(dict): ... pass >>> bananna = MyDict({"foo":"bar"}) #dict constructor still works >>> bananna.name = "bananna" >>> bananna.name 'bananna' >>> bananna {'foo': 'bar'} Or, you could also just do this: >>> bananna = {"name":"bananna"} Depending

Re: How do I read Excel file in Python?

2006-10-05 Thread Matimus
> the date( 8/9/2006 ) in Excel file, i am getting the value as 38938.0, > which I get when I convert date values to general format in Excel. I > want the actual date value. How do get that? 38938 appears to be the date in days since 1/1/1900. I'm sure someone can help you figure out how to conver

Re: Save/Store whole class (or another object) in a file

2006-10-17 Thread Matimus
> is it possible in python (with/without matplotlib, numpy etc) to store > a whole class with its data into a file, instead it to reconstruct > every time again? So is there an analogous to the matlab functions > load/save available? look up the pickle module. -- http://mail.python.org/mailman/l

Re: Exception Handling in TCPServer (was; Problem exiting application in Windows Console.)

2006-11-08 Thread Matimus
> This seems a really nasty hack though - any ideas for a cleaner way to > do it? You could overload handle_request instead. I think that makes more sense anyway because you don't want to handle a SystemExit exception as an error, you want to exit. Of course this only deals with catching the excep

Re: Will GPL Java eat into Python marketshare?

2006-11-15 Thread Matimus
John Bokma wrote: > Intelligent people don't suffer from fanboy sentiments. They just pick a > language that works best for them. Adding to that, they pick the language that works best for them and the situation. Python has a significant advantage in many applications because it is dynamic and ca

Re: About alternatives to Matlab

2006-11-16 Thread Matimus
Boris wrote: > Hi, is there any alternative software for Matlab? Although Matlab is > powerful & popular among mathematical & engineering guys, it still > costs too much & not publicly open. So I wonder if there's similar > software/lang that is open & with comparable functionality, at least

Re: How to let a loop run for a while before checking for break condition?

2006-08-29 Thread Matimus
Claudio Grondi wrote: > Sometimes it is known in advance, that the time spent in a loop will be > in order of minutes or even hours, so it makes sense to optimize each > element in the loop to make it run faster. > One of instructions which can sure be optimized away is the check for > the break c

Re: Data sticking around too long

2006-09-06 Thread Matimus
taskName and scanList are defined at the class level making them class attributes. Each instance of the ScannerCommand class will share its class attributes. What you want are instance attributes which can be initialized whithin the constructor like so: >>> class ScannerCommand: ... def __init

Re: Data sticking around too long

2006-09-06 Thread Matimus
Someone correct me if I'm wrong (sometimes I get the terms mixed up) but I believe that what you are seeing is due to 'number' being an immutable type. This means that its value cannot be changed and thus each assignment is effectively creating a new instance if int. I believe lists are considered

Re: I wish I could add docstrings to vars.

2006-09-12 Thread Matimus
It seems that you are getting some complex answers with confusing examples. So, here is hopefully a less confusing example: class MyDict(dict): """MyDict doc-string!""" #then to use it d = MyDict() d['something'] = whatever you want This solution leaves it open to do whatever you want with

Re: Help

2006-09-18 Thread Matimus
I have yet to find a language/community with better online documentation. I taught myself with the Python tutorial found at http://docs.python.org/tut/tut.html. I would look there first. If you are new to programming altogether I think Python may still be a good choice, but that may not be the _bes

Re: Trying to run an external program

2006-09-20 Thread Matimus
Brant Sears wrote: > Hi. I'm new to Python and I am trying to use the latest release (2.5) > on Windows XP. > > What I want to do is execute a program and have the results of the > execution assigned to a variable. According to the documentation the > way to do this is as follows: > > import comman

Re: generator with subfunction calling yield

2006-09-27 Thread Matimus
The issue is that nn() does not return an iterable object. _nn() returns an iterable object but nothing is done with it. Either of the following should work though: def nn(): def _nn(): print 'inside' yield 1 print 'before' for i in _nn(): yield i print 'aft

Re: remove a list from a list

2006-11-17 Thread Matimus
> The solution so far is: > > for i in xrange(len(dirs), 0, -1): >if dirs[i-1].lower() in dirs_exclude: > del dirs[i-1] This won't affect much, but uses better style I think. Change: for i in xrange(len(dirs),0,-1): To: for i in reversed(xrange(len(dirs))): and then just use 'i' inst

Re: String formatters with variable argument length

2006-11-30 Thread Matimus
> Could it be as I fear, that it is impossible? p'shaw, you underestimate the power of the Python... I think this is a poor solution (I would go with the solution in John Machin's second post) but here it is anyway since it does essentially what you asked for: [code] def print_data(fmtstr):

Re: Mirror imaging binary numbers

2006-12-06 Thread Matimus
Craig wrote: > I'm trying to switch binary numbers around so that the MSB becomes the > LSB etc. What do you mean 'binary numbers'? They are all binary. If you mean the int type, they are 32 bits long and there are 16 bits between the MSB and LSB (Most/Least Significant _Byte_). Do you want to swa

Re: Sorting Multidimesional array(newbie)

2006-12-11 Thread Matimus
Tartifola wrote: > Hi, > how can I sort an array like > > array([[5, 2], >[1, 3]]) > > along the first column to obtain > > array([[1, 3], >[5, 2]]) > i.e. keeping track of the ordered couples? > > Thanks, > A use a sort key: >>>from operators import getitem >>>a = [[5,2],[1,3]] >

Re: TypeError: unbound method must be called with class instance 1st argument

2006-12-20 Thread Matimus
> Can someone please explain why I get the following error: The following line: threading.Thread.__init__() Should be written as: threading.Thread.__init__(self) -- http://mail.python.org/mailman/listinfo/python-list

Re: list1.append(list2) returns None

2006-12-21 Thread Matimus
Pyenos wrote: > def enlargetable(table,col): > table.append(col) # the code won't return sorted lists :-o > return_the_fucking_table_bitch=table # assign it to a new variable to > return it > return return_the_fucking_table_bitch # :-| Maybe you were just trying to be funny, but ass

Re: A stupid question

2006-12-29 Thread Matimus
[EMAIL PROTECTED] wrote: > Any other ideas? Well, you could always try downloading and installing python: http://www.python.org. It is completely free. It won't run anything in the task bar or add itself to the startup menu and it doesn't have ads... it just sits there waiting for you to use it. I

Re: how to use execfile with argument under windows

2007-01-02 Thread Matimus
> > error output > IOError: [Errno 2] No such file or directory:"filename.exe -type png > -source sourcearg -file filename.png" Use 'os.system' not 'execfile'. 'execfile' is for executing other python scripts, not arbitrary command line. Try this: import os ... ... os.system("filename.exe -type

Re: C/C++, Perl, etc. to Python converter

2007-01-03 Thread Matimus
I don't know of a converter, one may exist. I have seen similar requests though and will give you a similar response to what I have seen. A converter, if it exists, may be able to produce working code but _not_ readable code. Python is a language whose strength comes from, among other things, its r

Re: code optimization (calc PI)

2007-01-03 Thread Matimus
Using the '+' operator for string concatonation can be slow, especially when done many times in a loop. >pi = pi + str("%04d" % int(e + d/a)) ## this should be fast?! I dont The accepted solution would be to make pi an array and append to the end... pi = [] #create the array (empty) ... ...

Re: code optimization (calc PI)

2007-01-03 Thread Matimus
> If someone is really interested in speed optimization, I can publish my > PI-calc code. I wouldn't mind seeing it. Chances are you will get much better help if you post your code anyway. -Matt -- http://mail.python.org/mailman/listinfo/python-list

Re: Determine an object is a subclass of another

2007-01-09 Thread Matimus
First you need to subclass the classes so that Dog actually is a subclass of Animal which is a subclass of thing... class Thing: pass class Animal(Thing): pass class Dog(Animal): pass class Weapon(Thing): pass class Gun(Weapon): pass Then you can use 'isinstance' >>>d = Dog() >>>is

Re: Get ClassID of different versions of program with same ProgID

2007-06-01 Thread Matimus
Bummer you can't look into the registry. By convention the ProgID is named ... Also, usually there is a version independent ProgID that goes .. The version independent ProgID usually points to the newest version. It looks like that is what you are using. Many programs get away with not using those

Re: How do you htmlentities in Python

2007-06-04 Thread Matimus
On Jun 4, 6:31 am, "js " <[EMAIL PROTECTED]> wrote: > Hi list. > > If I'm not mistaken, in python, there's no standard library to convert > html entities, like & or > into their applicable characters. > > htmlentitydefs provides maps that helps this conversion, > but it's not a function so you have

Re: Sending cookies with python. When download with python

2007-06-05 Thread Matimus
On Jun 5, 9:14 am, [EMAIL PROTECTED] wrote: > I need to download files off a password protected website. So if I try > to download files off the site with python I will be blocked. Is there > anyway to send cookies with python. So I will be authenticated. Yes. I haven't done it but I know you shou

Re: which "GUI module" you suggest me to use?

2007-06-05 Thread Matimus
> I know that WxPython work only under Windows Hmm, there seems to be some disparity between what you know and the truth... WxPython works everywhere (Windows, Linux, MacOS), and it works well. Also, it has web widgets that come standard (wx.html.HtmlWindow). Matt -- http://mail.python.org/mai

Re: Does Boost.Python participate in cyclic gc?

2007-06-05 Thread Matimus
> The solution was to recognize when we where finished with it to set > self.over_there to None. To my knowledge python does not handle all cyclic gc anyway. Here is some information from the gc documentation: [doc] garbage A list of objects which the collector found to be unreachable but could

Re: copying generatrors

2007-06-05 Thread Matimus
Why not just do this: >>> def foo(): ... yield 1 ... yield 2 ... yield 3 ... >>> f = foo() >>> g = foo() >>> f.next() 1 >>> f.next() 2 >>> f.next() 3 >>> g.next() 1 >>> g.next() 2 >>> g.next() 3 -- http://mail.python.org/mailman/listinfo/python-list

Re: running a random function

2007-06-07 Thread Matimus
How are you making the list of functions? Something like this: [code] fs = [] for k,f in globals(): if callable(f): fs.append(f) [/code] Then to call a random one (assuming they all take no parameters): [code] import random random.choice(fs)() [/code] Or maybe you only have the name

Re: Method much slower than function?

2007-06-14 Thread Matimus
> The first time you read the file, it has to read it from disk. > The second time, it's probably just reading from the buffer > cache in RAM. I can verify this type of behavior when reading large files. Opening the file doesn't take long, but the first read will take a while (multiple seconds dep

Re: Making static dicts?

2007-06-18 Thread Matimus
On Jun 18, 1:46 pm, Ognjen Bezanov <[EMAIL PROTECTED]> wrote: > Hello! > > Just to ask, is it possible to make a static dictionary in python. So > that the keys in the dictionary cannot be removed, changed or new ones > added, but the value pairs can. > > Is this possible with python? > > thanks, >

Re: need help with re module

2007-06-20 Thread Matimus
On Jun 20, 9:58 am, linuxprog <[EMAIL PROTECTED]> wrote: > hello > > i have that string "helloworldok" and i want to > extract all the text , without html tags , the result should be some > thing like that : helloworldok > > i have tried that : > > from re import findall > > chaine

Re: need help with re module

2007-06-20 Thread Matimus
Here is an example: >>> s = "Helloworldok" >>> matchtags = re.compile(r"<[^>]+>") >>> matchtags.findall(s) ['', '', ''] >>> matchtags.sub('',s) 'Helloworldok' I probably shouldn't have shown you that. It may not work for all HTML, and you should probably be looking at something like BeautifulSoup

Re: try/except with multiple files

2007-06-21 Thread Matimus
It depends, what are you going to do if there is an exception? If you are just going to exit the program, then that works fine. If you are going to just skip that file, then the above wont work. If you are going to return to some other state in your program, but abort the file opening, you might wa

Re: howto run a function w/o text output?

2007-06-22 Thread Matimus
On Jun 22, 9:56 am, dmitrey <[EMAIL PROTECTED]> wrote: > hi all, > I have a > y = some_func(args) > statement, and the some_func() produces lots of text output. Can I > somehow to suppress the one? > Thx in advance, D. [code] import sys import os sys.stdout = open(os.devnull,"w") [/code] -- htt

Re: server wide variables

2007-06-25 Thread Matimus
On Jun 25, 8:29 am, Jay Sonmez <[EMAIL PROTECTED]> wrote: > I want to be able to save some server variables as long as Apache runs > on the server (mod_python). > > How is that possible in Python? I don't have any experience with mod_python, but I'm assuming all of the standard python modules are

Re: problem mixing gettext and properties

2007-06-26 Thread Matimus
On Jun 26, 10:52 am, André <[EMAIL PROTECTED]> wrote: > I've encountered a problem using gettext with properties while using a > Python interpreter. > > Here's a simple program that illustrate the problem. > == > # i18n_test.py: test of gettext & properties > > import gettext > > fr = g

Re: noob question How do I run a Python script.

2007-06-28 Thread Matimus
> I installed python, run the interpreter and the script... Are you trying to run the script from the interpreter? You _can_ run scripts from the interpreter, but it isn't as simple as typing the name of the script. To me, that is what it sounds like you are trying to do. I don't know what environ

Re: Restarting a Python Application

2007-07-03 Thread Matimus
On Jul 3, 2:27 pm, [EMAIL PROTECTED] wrote: > Hi, > > I packaged up an application I am developing into an executable. In > the application, it has user configurable options. I would like a way > to restart the application so that the new options the user chooses > can be applied. Firefox can resta

Re: Expandable 2D Dictionaries?

2007-07-06 Thread Matimus
I'm not sure I completely understand what you want, but if you are using Python2.5 defaultdict might be useful. Below is some example code using defaultdict. [code] from collections import defaultdict myvar = defaultdict(dict) myvar["cat"]["paw"] = "SomeString" myvar["dog"]["tail"] = "wags" myv

Re: Restarting a Python Application

2007-07-07 Thread Matimus
> Actually I am using wxPython for a GUI front-end. Thus, it is already > in a class. I am not sure how to apply your idea to a program that is > already running in an infinite event loop. I don't know wxPython, but I was able to grab an example program and adapt it to do what I think you are ask

Re: SafeConfigParser can set unsafe values

2007-07-10 Thread Matimus
> Should SafeConfigParser.set() be escaping automatically? It seems like that would be a nice feature. However, may I offer up that if you are setting an option and then later on getting that value back in the same program, you probably should have used some other storage mechanism in the first pl

Re: SafeConfigParser can set unsafe values

2007-07-10 Thread Matimus
> I agree, but that was a trivial example to demonstrate the problem. > Writing the file out to disk writes it exactly as set(), causing a get() > to fail just the same later. No... The above statement is not true. The following code: [code] from ConfigParser import * import sys cp = SafeConfig

Re: SafeConfigParser can set unsafe values

2007-07-10 Thread Matimus
> This not only happens when get() after a set(), but with all the use cases > above. An intervening write()/read() does not change things. > But I'm not sure it is a bug really. If all % were escaped automatically, > there is no way to write a templatized value. Maybe SafeConfigParser.set > should

Re: SafeConfigParser can set unsafe values

2007-07-10 Thread Matimus
> This not only happens when get() after a set(), but with all the use cases > above. An intervening write()/read() does not change things. > But I'm not sure it is a bug really. If all % were escaped automatically, > there is no way to write a templatized value. Maybe SafeConfigParser.set > should

Re: Fastest way to convert a byte of integer into a list

2007-07-12 Thread Matimus
On Jul 12, 3:34 pm, Godzilla <[EMAIL PROTECTED]> wrote: > Hello, > > I'm trying to find a way to convert an integer (8-bits long for > starters) and converting them to a list, e.g.: > > num = 255 > numList = [1,1,1,1,1,1,1,1] > > with the first element of the list being the least significant, so >

Re: Break up list into groups

2007-07-16 Thread Matimus
This is a perfect place for a generator: seq = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6, 0xF1, 7, 8, 0xF2, 9, 10, 11, 12, 13, 0xF0, 14, 0xF1, 15] def gengroups(seq): group = [] for val in seq: if val & 0x80 and group: yield group group = [] group.append(val)

Re: Semantics of file.close()

2007-07-16 Thread Matimus
> How do I ensure that the close() methods in my finally clause do not > throw an exception? You have no choice. If close is going to fail, it will fail. Fortunately you can catch the exception and continue on. try: try: file1.write(somestuff) finally: file1.close() except

Re: In a dynamic language, why % operator asks user for type info?

2007-07-16 Thread Matimus
I don't have a good answer for you, but you might be interested to read this: http://python.org/dev/peps/pep-3101/. Which according to a recent blog post by BDFL is going to be how string formatting is done in Python3000. The character doesn't specify the type to expect, but the formatting functio

Re: Break up list into groups

2007-07-17 Thread Matimus
I did some more experimenting and came up with the code below. It shows several methods. When run, the script tests the robustness of each method (roughly), and profiles it using timeit. The results from running on my laptop are shown below the code. seqs = [# Original: [0xF0, 1, 2, 3, 0

Re: Break up list into groups

2007-07-19 Thread Matimus
> A little renaming of variables helps it be a bit more elegant I think ... > > def getgroups8(seq): > groups = [] > iseq = iter(xrange(len(seq))) > for start in iseq: > if seq[start] & 0x80: > for stop in iseq: > if seq[stop] & 0x80: >

Re: Is it possible to merge xrange and slice?

2007-04-30 Thread Matimus
> Which problems am I overlooking that prevent this? 1. Generators and slices serve two distinctly different tasks. 2. They may have the similar interfaces, but are implemented differently. Each optimized for its specific task. You are essentially asking "Why not do it?", to which I respond "Why

Re: Python user group in Portland, OR?

2007-05-01 Thread Matimus
Python.org lists PORPIG (PORtland Python Intrest Group) but the site that it points to no longer seems to represent that. Also, when I looked into going to a meeting a while back, the last one listed was some time in 2004. I will put this out there though, if someone wants to start a PIG back up fo

Re: Time functions

2007-05-02 Thread Matimus
On May 2, 10:21 am, HMS Surprise <[EMAIL PROTECTED]> wrote: > On May 2, 12:03 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > > > In <[EMAIL PROTECTED]>, HMS Surprise > > wrote: > > > > I wish to generate a datetime string that has the following format. > > > '05/02/2007 12:46'. The leadi

Re: Slicing Arrays in this way

2007-05-02 Thread Matimus
On May 2, 3:03 pm, Tobiah <[EMAIL PROTECTED]> wrote: > >>> elegant_solution([1,2,3,4,5,6,7,8,9,10]) > [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]] > > -- > Posted via a free Usenet account fromhttp://www.teranews.com >>> seq = range(1,11) >>> seq [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> zip( seq[0::2],se

Re: How to replace the last (and only last) character in a string?

2007-05-03 Thread Matimus
On May 3, 7:44 am, Johny <[EMAIL PROTECTED]> wrote: > On May 3, 4:37 pm, [EMAIL PROTECTED] wrote: > > > > > On May 3, 9:27 am, Johny <[EMAIL PROTECTED]> wrote: > > > > Let's suppose > > > s='12345 4343 454' > > > How can I replace the last '4' character? > > > I tried > > > string.replace(s,s[len(s

Re: Real Time Battle and Python

2007-05-03 Thread Matimus
On May 3, 5:20 am, hg <[EMAIL PROTECTED]> wrote: > Hi, > > I have started to work on a python-based robot, and am interested in your > feedback: > > http://realtimebattle.sourceforge.net/www.snakecard.com/rtb > > hg This is not necessarily a response to your effort, but just a note (rant) about re

Re: cannot import name .....

2007-05-03 Thread Matimus
I do see one problem there... if __name__ == 'main': t = nBaseTest('nBaseTest') t.logon() That should be: if __name__ == "__main__": t = nBaseTest('nBaseTest') t.logon() It should be like that in both files. -- http://mail.python.org/mailman/listinfo/python-list

Re: Trying to choose between python and java

2007-05-15 Thread Matimus
> #3 Is there any equivalent to jfreechart and jfreereport > (http://www.jfree.orgfor details) in python. I haven't used either extensively but you might check out ReportLab for report generation (http://www.reportlab.org). And MatPlotLib for creating plots, charts and graphs (http://matplotlib.so

Re: Trying to choose between python and java

2007-05-16 Thread Matimus
> I tend to use the shebang #!/usr/bin/env python in my scripts so far > but I imagine that having that would not work on say windows. Or is > there some kind of file extension association for people running > windows instead of the shebang? The shebang is ignored in Windows (as far as I know). Th

Re: Declaring variables

2007-05-16 Thread Matimus
On May 16, 9:57 am, HMS Surprise <[EMAIL PROTECTED]> wrote: > I looked in the language but did not find a switch for requiring > variables to be declared before use. > > Is such an option available? > > Thanks, > > jvh You do have to declare a variable before use. You do so by assigning it a value

Re: Newbie: Joining Lists

2007-05-17 Thread Matimus
One: Not that I know of Two: You could use list comprehension... --- CODE -- import os import glob patterns = ('.\\t*.py', '.\\*.c??', '.\\*.txt') filenames = [glob.glob(pat) for pat in patterns] # Or as a one liner... filenames = [glob.glob(pat) for pat

Re: A newbie question

2007-05-21 Thread Matimus
How about this: [code] def __add__(self,x): return Cc14(self.r+x.r, self.i+x.i) [/code] However... Are you aware that Python has built in support for complex numbers already? >>> x = 4+5j >>> y = 4+5j >>> x+y (8+10j) >>> -- http://mail.python.org/mailman/listinfo/python-list

Re: Create an XML document

2007-05-22 Thread Matimus
> How do I get Python to put values into the elements by tag name? The same way you create put in new elements. Only, you use 'doc.createTextNode' instead of 'doc.createElement' to create it. from xml.dom.minidom import Document doc = Document() zappt = doc.createElement('zAppointments') zap

Re: No file from stdin

2007-05-24 Thread Matimus
On May 24, 9:48 am, Tartifola <[EMAIL PROTECTED]> wrote: > Hi, > suppose a script of python is waiting for a file from the stdin and none > is given. How can I make the script to stop and, for example, print an > error message? > > Sorry for the n00b question and thanks I'm not exactly sure what y

Re: Large Amount of Data

2007-05-25 Thread Matimus
On May 25, 10:50 am, "Jack" <[EMAIL PROTECTED]> wrote: > I need to process large amount of data. The data structure fits well > in a dictionary but the amount is large - close to or more than the size > of physical memory. I wonder what will happen if I try to load the data > into a dictionary. Wil

Re: Rats! vararg assignments don't work

2007-05-29 Thread Matimus
Your attemtp: [code] first, rest = arglist[0], arglist[1:] [/code] Is the most obvious and probably the most accepted way to do what you are looking for. As for adding the fucntionality you first suggested, it isn't likely to be implemented. The first step would be to write a PEP though. Remember

Re: replace the base class

2007-05-30 Thread Matimus
This is a rather simplistic example, but you may be able to use a mixin class to achieve what you need. The idea is that you write a class that overrides only what is needed to add the new functionality. For you it would be Color. [code] class Graph(object): def _foo(self): print "Grap

Re: (sort of) deterministic timing in Python

2007-08-13 Thread Matimus
> Do you see the difference? I get a true fixed interval from the first, > including the time to accomplish the event task(s). In the second case, > the sleep just gets tacked on at the end of the events, not very > deterministic (timing-wise). Check out the sched (scheduler) module http://docs.p

Re: convert non-delimited to delimited

2007-08-27 Thread Matimus
On Aug 27, 10:59 am, RyanL <[EMAIL PROTECTED]> wrote: > I'm a newbie! I have a non-delimited data file that I'd like to > convert to delimited. > > Example... > Line in non-delimited file: > 01397256359210100534+42050-102800FM-15+1198KAIA > > Should be: > 0139,725635,9,2000,01,01,00,53

Re: Pythonic way of reading a textfile line by line without throwing an exception

2007-08-28 Thread Matimus
> fp=open(filename, 'r') > for line in fp: > # do something with line > > fp.close() Or, if you are using Python 2.5+, you can use the file context via the `with' statement. [code] from __future__ import with_statement # this line won't be needed in Python 2.6+ with open(filename, 'r') as fp

Re: Haskell like (c:cs) syntax

2007-08-28 Thread Matimus
> Is there a pattern matching construct in Python like (head : tail), meaning > 'head' matches the first element of a list and 'tail' matches the rest? I > could not find this in the Python documentation. Not really, but you could do something like this: [code] def foo(head, *tail): #do stuff

Re: Registering a python function in C

2007-08-30 Thread Matimus
On Aug 30, 2:21 pm, fernando <[EMAIL PROTECTED]> wrote: > Could someone post an example on how to register a python function as > a callback in a C function? It expects a pointer to PyObject... how do > I expose that? Basically, the signature of the function is > foo(PyObject* obj), where obj is th

Re: Python is overtaking Perl

2007-09-04 Thread Matimus
> So I think we can at least say from the chart that searches combining > the terms 'python' and 'programming' have been falling, by some > unquantifiable amount (it don't _look_ like much!?), relative to the > number of total searches. I think it is the search volume relative to the total number

Re: Subclassing zipfile (new style class)

2007-09-06 Thread Matimus
> import zipfile > class walkZip(zipfile): > pass > > if __name__ == "__main__": > print "Hello World" `zipfile' is the name of the module, not a class. What you probably want is this: [code] import zipfile class WalkZip(zipfile.ZipFile): pass if __name__ == "__main__": print

Re: Question about PEP 8

2007-09-10 Thread Matimus
> will Py3K change the standard library names in order to follow PEP 8?) Just continue down the list of PEPs and you will find the answer: http://www.python.org/dev/peps/pep-3108/#modules-to-rename This covers built-in modules. It doesn't cover 3rd party modules, like wx. Most likely you will st

Re: Is every number in a list in a range?

2007-03-05 Thread Matimus
On Mar 5, 11:03 am, "Steven W. Orr" <[EMAIL PROTECTED]> wrote: > I have a list ll of intergers. I want to see if each number in ll is > within the range of 0..maxnum > > I can write it but I was wondering if there's a better way to do it? > > TIA > > -- > Time flies like the wind. Fruit flies like

Re: Is every number in a list in a range?

2007-03-05 Thread Matimus
On Mar 5, 1:34 pm, "Matimus" <[EMAIL PROTECTED]> wrote: > On Mar 5, 11:03 am, "Steven W. Orr" <[EMAIL PROTECTED]> wrote: > > > I have a list ll of intergers. I want to see if each number in ll is > > within the range of 0..maxnum > > > I

Re: Flatten a two-level list --> one liner?

2007-03-07 Thread Matimus
> Any ideas? how about list comprehension (should actually work even if there is an empty sub-list): >>> spam = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]] >>> [parrot for egg in spam for parrot in egg] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] -m -- http://mail.python.org/mailman/listinfo/python-list

Re: Where to "import"?

2007-03-08 Thread Matimus
> both using os module where should I put the "import os"? In both files? You don't really have a choice, you have to import os in both files. Python will only load the os module into memory once, but the import statements are needed to add the os module to the c and m module namespaces. The code

Re: problem with str()

2007-03-15 Thread Matimus
Don't use built-ins as variable names. Your code will work if you change this: > methodList = [str for str in names if callable(getattr(obj, str))] to this: > methodList = [s for s in names if callable(getattr(obj, s))] -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter menu toplevel or frame

2007-03-15 Thread Matimus
> Please tell me is here anything that I should change. The way you have written it, master _must_ be a Toplevel object. So, maybe parent is the correct name, but it doesn't really matter. As a side note, there is no reason for this class to inherit Frame. Aside from packing and sizing the frame,

Re: To count number of quadruplets with sum = 0

2007-03-15 Thread Matimus
> Any ideas to speed it up say 10 times? Or the problem only for C-like > langs? I dout this will speed it up by a factor of 10, but in your solution you are mapping the values in the input file to longs. The problem statement states that the maximum value for any of the numbers is 2**28. I assume

Re: Finding the insertion point in a list

2007-03-16 Thread Matimus
You might look at the bisect module (part of the standard distribution). -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding the insertion point in a list

2007-03-16 Thread Matimus
On Mar 16, 11:20 am, "Matimus" <[EMAIL PROTECTED]> wrote: > You might look at the bisect module (part of the standard > distribution). Here is an example: >>> from bisect import insort >>> x = [0,100,200,1000] >>> insort(x,10) >>> x [

Re: Python C extension providing... Python's own API?

2007-03-26 Thread Matimus
On Mar 26, 12:21 pm, "Adam Atlas" <[EMAIL PROTECTED]> wrote: > Does anyone know if it would be possible to create a CPython extension > -- or use the ctypes module -- to access Python's own embedding API > (http://docs.python.org/api/initialization.html&c.)? Could a Python > program itself create a

Re: Parallel ping problems python puzzler

2007-04-02 Thread Matimus
I wouldn't use threads for system calls. Checkout the subprocess module instead. You can run multiple pipes at the same time (subprocess.Popen). The python documentation for subprocess is pretty good. There are a few examples. Actually, you don't even _need_ the subprocess module, you can use os.po

Re: Stack experiment

2007-04-03 Thread Matimus
On Apr 3, 8:57 am, [EMAIL PROTECTED] wrote: > Hi! Im new to Python and doing exercise found from internet. It is > supposed to evaluate expression given with postfix operator using > Stack() class. > > class Stack: > def __init__(self): > self.items = [] > > def push(self, item):

Re: how to remove multiple occurrences of a string within a list?

2007-04-03 Thread Matimus
It depends on your application, but a 'set' might really be what you want, as opposed to a list. >>> s = set(["0024","haha","0024"]) >>> s set(["0024","haha"]) >>> s.remove("0024") >>> s set(["haha"]) -- http://mail.python.org/mailman/listinfo/python-list

Re: how to remove multiple occurrences of a string within a list?

2007-04-03 Thread Matimus
On Apr 3, 12:13 pm, "bahoo" <[EMAIL PROTECTED]> wrote: > On Apr 3, 2:31 pm, "Matimus" <[EMAIL PROTECTED]> wrote: > > > It depends on your application, but a 'set' might really be what you > > want, as opposed to a list. > > >

Re: OT: Question about RGB color method

2007-04-10 Thread Matimus
On Apr 10, 12:32 pm, John Salerno <[EMAIL PROTECTED]> wrote: > Sorry for this non-Python question, but since it's computer related I > know you guys will have an answer, and I don't really know where else to > ask. Mainly I'm just curious anyway. > > I'm wondering, why do computers use a RGB color

Re: reading from sys.stdin

2007-04-12 Thread Matimus
On Apr 12, 1:20 am, "7stud" <[EMAIL PROTECTED]> wrote: > I can't break out of the for loop in this example: > > -- > import sys > > lst = [] > for line in sys.stdin: > lst.append(line) > break > > print lst > --- > > But, I can break out of the for loop when I do this: > > -

Re: reading from sys.stdin

2007-04-12 Thread Matimus
On Apr 12, 8:20 am, Maric Michaud <[EMAIL PROTECTED]> wrote: > Le jeudi 12 avril 2007 16:25, Matimus a écrit : > > > # Then you check to see if your file is interactive > > if f.isatty(): > > # This is unbuffered, and will iterate the same as f > > f =

Re: comparing elements of a list with a string

2007-09-25 Thread Matimus
Shriphani wrote: > Hello all, > I have a problem here. I have a list named list_of_files which > contains filenames with their timestamps attached to the name. If I > have a string "fstab", and I want to list out the files in whose names > the word fstab appears should I go about like this : > > d

Re: Python class method as an argument of a function in a C extension

2007-09-26 Thread Matimus
> Can anybody give me an hint (or some link) on how to define > 'aCFunction' and how to call 'self.myMethod' in the C source code? A python function defined in C accepts a pointer to self and a tuple of arguments, each of which is also a PyObject. If you pass a function or method, it will be inclu

  1   2   3   >