Re: Parsing a serial stream too slowly

2012-01-23 Thread Jon Clements
On Jan 23, 9:48 pm, "M.Pekala" wrote: > Hello, I am having some trouble with a serial stream on a project I am > working on. I have an external board that is attached to a set of > sensors. The board polls the sensors, filters them, formats the > values, and sends the formatted values over a seria

Re: Find the mime type of a file.

2012-01-25 Thread Jon Clements
On Jan 25, 5:04 pm, Olive wrote: > I want to have a list of all the images in a directory. To do so I want > to have a function that find the mime type of a file. I have found > mimetypes.guess_type but it only works by examining the extension. In > GNU/Linux the "file" utility do much better by a

Re: Constraints -//- first release -//- Flexible abstract class based validation for attributes, functions and code blocks

2012-01-27 Thread Jon Clements
On Jan 27, 6:38 am, Nathan Rice wrote: > > May I suggest a look at languages such as ATS and Epigram? They use > > types that constrain values specifically to prove things about your > > program. Haskell is a step, but as far as proving goes, it's less > > powerful than it could be. ATS allows you

Re: os.stat last accessed attribute updating last accessed value

2012-02-06 Thread Jon Clements
On Feb 4, 9:33 pm, Python_Junkie wrote: > I am trying to obtain the last accessed date.  About 50% of the files' > attributes were updated such that the file was last accessed when this > script touches the file. > I was not opening the files > > Anyone have a thought of why this happened. > > Pyt

Re: Finding MIME type for a data stream

2012-03-08 Thread Jon Clements
On Thursday, 8 March 2012 23:40:13 UTC, Tobiah wrote: > > I have to assume you're talking python 2, since in python 3, strings > > cannot generally contain image data. In python 2, characters are pretty > > much interchangeable with bytes. > > Yeah, python 2 > > > > if you're looking for a s

Re: Fast file data retrieval?

2012-03-12 Thread Jon Clements
On Monday, 12 March 2012 20:31:35 UTC, MRAB wrote: > On 12/03/2012 19:39, Virgil Stokes wrote: > > I have a rather large ASCII file that is structured as follows > > > > header line > > 9 nonblank lines with alphanumeric data > > header line > > 9 nonblank lines with alphanumeric data > > ... > >

Re: How to decide if a object is instancemethod?

2012-03-14 Thread Jon Clements
On Wednesday, 14 March 2012 13:28:58 UTC, Cosmia Luna wrote: > class Foo(object): > def bar(self): > return 'Something' > > func = Foo().bar > > if type(func) == : # This should be always true > pass # do something here > > What should type at ? > > Thanks > Cosmia import insp

Re: Jinja2 + jQuery tabs widget

2012-03-14 Thread Jon Clements
On Wednesday, 14 March 2012 14:16:35 UTC, JoeM wrote: > Hi All, > > I'm having issues including a {block} of content from Jinja2 > template into a jQueryUI tab. Does anyone know if such a thing is > possible? An example is below, which gives me a 500 error when loading > the page. > > Thank

Re: Global join function?

2012-03-14 Thread Jon Clements
On Wednesday, 14 March 2012 18:41:27 UTC, Darrel Grant wrote: > In the virtualenv example bootstrap code, a global join function is used. > > http://pypi.python.org/pypi/virtualenv > > subprocess.call([join(home_dir, 'bin', 'easy_install'), > 'BlogApplication']) > > >

Re: Style question (Poll)

2012-03-15 Thread Jon Clements
On Wednesday, 14 March 2012 21:16:05 UTC, Terry Reedy wrote: > On 3/14/2012 4:49 PM, Arnaud Delobelle wrote: > > On 14 March 2012 20:37, Croepha wrote: > >> Which is preferred: > >> > >> for value in list: > >> if not value is another_value: > >> value.do_something() > >> break > > Do

Re: urllib.urlretrieve never returns???

2012-03-19 Thread Jon Clements
On Monday, 19 March 2012 19:32:03 UTC, Laszlo Nagy wrote: > The pythonw.exe may not have the rights to access network resources. > >> Have you set a default timeout for sockets? > >> > >> import socket > >> socket.setdefaulttimeout(10) # 10 seconds > I have added pythonw.exe to allowed exceptions.

Re: Python is readable (OT)

2012-03-22 Thread Jon Clements
On Thursday, 22 March 2012 08:56:17 UTC, Steven D'Aprano wrote: > On Wed, 21 Mar 2012 18:35:16 -0700, Steve Howell wrote: > > > On Mar 21, 11:06 am, Nathan Rice > > wrote: [snip]. > > Different programming languages are good for different things because > they have been designed to work in dif

Re: Data mining/pattern recogniton software in Python?

2012-03-23 Thread Jon Clements
On Friday, 23 March 2012 16:43:40 UTC, Grzegorz Staniak wrote: > Hello, > > I've been asked by a colleague for help in a small educational > project, which would involve the recognition of patterns in a live > feed of data points (readings from a measuring appliance), and then > a more general

Re: Fetching data from a HTML file

2012-03-23 Thread Jon Clements
On Friday, 23 March 2012 13:52:05 UTC, Sangeet wrote: > Hi, > > I've got to fetch data from the snippet below and have been trying to match > the digits in this to specifically to specific groups. But I can't seem to > figure how to go about stripping the tags! :( > > Sum class="green">24511 a

Re: Best way to structure data for efficient searching

2012-04-02 Thread Jon Clements
On Wednesday, 28 March 2012 19:39:54 UTC+1, larry@gmail.com wrote: > I have the following use case: > > I have a set of data that is contains 3 fields, K1, K2 and a > timestamp. There are duplicates in the data set, and they all have to > processed. > > Then I have another set of data with 4

Re: help with subclassing problem

2012-04-02 Thread Jon Clements
On Thursday, 29 March 2012 21:23:20 UTC+1, Peter wrote: > I am attempting to subclass the date class from the datetime package. > Basically I want a subclass that can take the date as a string (in multiple > formats), parse the string and derive the year,month and day information to > create a

Re: Async IO Server with Blocking DB

2012-04-04 Thread Jon Clements
On Tuesday, 3 April 2012 23:13:24 UTC+1, looking for wrote: > Hi > > We are thinking about building a webservice server and considering > python event-driven servers i.e. Gevent/Tornado/ Twisted or some > combination thereof etc. > > We are having doubts about the db io part. Even with connectio

Re: Python Gotcha's?

2012-04-05 Thread Jon Clements
On Wednesday, 4 April 2012 23:34:20 UTC+1, Miki Tebeka wrote: > Greetings, > > I'm going to give a "Python Gotcha's" talk at work. > If you have an interesting/common "Gotcha" (warts/dark corners ...) please > share. > > (Note that I want over http://wiki.python.org/moin/PythonWarts already). >

ordering with duck typing in 3.1

2012-04-07 Thread Jon Clements
Any reason you can't derive from int instead of object? You may also want to check out functions.total_ordering on 2.7+ -- http://mail.python.org/mailman/listinfo/python-list

Re: ordering with duck typing in 3.1

2012-04-09 Thread Jon Clements
On Monday, 9 April 2012 12:33:25 UTC+1, Neil Cerutti wrote: > On 2012-04-07, Jon Clements wrote: > > Any reason you can't derive from int instead of object? You may > > also want to check out functions.total_ordering on 2.7+ > > functools.total_ordering > > I w

Re: escaping

2012-04-16 Thread Jon Clements
On Monday, 16 April 2012 11:03:31 UTC+1, Kiuhnm wrote: > On 4/16/2012 4:42, Steven D'Aprano wrote: > > On Sun, 15 Apr 2012 23:07:36 +0200, Kiuhnm wrote: > > > >> This is the behavior I need: > >> path = path.replace('\\', '') > >> msg = ". {} .. '{}' .. {} .".format(a, path, b) > >

Re: Regular expressions, help?

2012-04-19 Thread Jon Clements
On Thursday, 19 April 2012 07:11:54 UTC+1, Sania wrote: > Hi, > So I am trying to get the number of casualties in a text. After 'death > toll' in the text the number I need is presented as you can see from > the variable called text. Here is my code > I'm pretty sure my regex is correct, I think i

Re: How do you refer to an iterator in docs?

2012-04-19 Thread Jon Clements
On Thursday, 19 April 2012 13:21:20 UTC+1, Roy Smith wrote: > Let's say I have a function which takes a list of words. I might write > the docstring for it something like: > > def foo(words): >"Foo-ify words (which must be a list)" > > What if I want words to be the more general case of so

Re: Using arguments in a decorator

2012-04-20 Thread Jon Clements
On Friday, 20 April 2012 16:57:06 UTC+1, Rotwang wrote: > Hi all, here's a problem I don't know how to solve. I'm using Python 2.7.2. > > I'm doing some stuff in Python which means I have cause to call > functions that take a while to return. Since I often want to call such a > function more th

Re: Using arguments in a decorator

2012-04-21 Thread Jon Clements
On Saturday, 21 April 2012 09:25:40 UTC+1, Steven D'Aprano wrote: > On Fri, 20 Apr 2012 09:10:15 -0700, Jon Clements wrote: > > >> But I don't know how. I know that I can see the default arguments of > >> the original function using func.__defaults__, but w

Re: Newbie, homework help, please.

2012-04-21 Thread Jon Clements
On Saturday, 21 April 2012 18:35:26 UTC+1, someone wrote: > On Saturday, April 21, 2012 12:28:33 PM UTC-5, someone wrote: > > Ok, this is my dillema, not only am I new to this programming buisness, > > before the last few days, I did not even know what python was, and besides > > opening up the

Re: Web Scraping - Output File

2012-04-26 Thread Jon Clements
comcast.net> writes: > > Hello, > > I am having some difficulty generating the output I want from web > scraping. Specifically, the script I wrote, while it runs without any > errors, is not writing to the output file correctly. It runs, and > creates the output .txt file; however, the file is

Re: HTML Code - Line Number

2012-04-27 Thread Jon Clements
comcast.net> writes: > > Hello, > [snip] > Any thoughts as to how to define a function to do this, or do this > some other way? All insight is much appreciated! Thanks. > Did you not see my reply to your previous thread? And why do you want the line number? Jon. -- http://mail.python.or

Re: HTML Code - Line Number

2012-04-27 Thread Jon Clements
On Friday, 27 April 2012 18:09:57 UTC+1, smac...@comcast.net wrote: > Hello, > > For scrapping purposes, I am having a bit of trouble writing a block > of code to define, and find, the relative position (line number) of a > string of HTML code. I can pull out one string that I want, and then > th

Re: key/value store optimized for disk storage

2012-05-05 Thread Jon Clements
On Friday, 4 May 2012 16:27:54 UTC+1, Steve Howell wrote: > On May 3, 6:10 pm, Miki Tebeka wrote: > > > I'm looking for a fairly lightweight key/value store that works for > > > this type of problem: > > > > I'd start with a benchmark and try some of the things that are already in > > the standa

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Jon Clements
On Monday, 21 May 2012 13:37:29 UTC+1, Roy Smith wrote: > I've got this code in a django app: > > CHOICES = [ > ('NONE', 'No experience required'), > ('SAIL', 'Sailing experience, new to racing'), > ('RACE', 'General racing experience'), > ('GOOD', 'Experienced

Re: Email Id Verification

2012-05-25 Thread Jon Clements
On Friday, 25 May 2012 14:36:18 UTC+1, Grant Edwards wrote: > On 2012-05-25, Steven D'Aprano wrote: > > On Thu, 24 May 2012 05:32:16 -0700, niks wrote: > > > >> Hello everyone.. > >> I am new to asp.net... > >> I want to use Regular Expression validator in Email id verification.. > > > > Why do y

Re: Dynamic comparison operators

2012-05-25 Thread Jon Clements
> > Any time you find yourself thinking that you want to use eval to solve a > problem, take a long, cold shower until the urge goes away. > > If you have to ask why eval is dangerous, then you don't know enough > about programming to use it safely. Scrub it out of your life until you > have l

usenet reading

2012-05-25 Thread Jon Clements
Hi All, Normally use Google Groups but it's becoming absolutely frustrating - not only has the interface changed to be frankly impractical, the posts are somewhat random of what appears, is posted and whatnot. (Ironically posted from GG) Is there a server out there where I can get my news group

Re: sqlite INSERT performance

2012-05-31 Thread Jon Clements
On Thursday, 31 May 2012 16:25:10 UTC+1, duncan smith wrote: > On 31/05/12 06:15, John Nagle wrote: > > On 5/30/2012 6:57 PM, duncan smith wrote: > >> Hello, > >> I have been attempting to speed up some code by using an sqlite > >> database, but I'm not getting the performance gains I expected. >

Re: DBF records API

2012-06-01 Thread Jon Clements
On 01/06/12 23:13, Tim Chase wrote: On 06/01/12 15:05, Ethan Furman wrote: MRAB wrote: I'd probably think of a record as being more like a dict (or an OrderedDict) with the fields accessed by key: record["name"] but: record.deleted Record fields are accessible both by key and by

Re: file pointer array

2012-06-06 Thread Jon Clements
On 06/06/12 18:54, Prasad, Ramit wrote: data= [] for index in range(N, 1): # see Chris Rebert's comment with open('data%d.txt' % index,'r') as f: data.append( f.readlines() ) I think "data.extend(f)" would be a better choice. Jon. -- http://mail.python.org/mailman/listinfo/pytho

Re: file pointer array

2012-06-06 Thread Jon Clements
On 06/06/12 19:51, MRAB wrote: On 06/06/2012 19:28, Jon Clements wrote: On 06/06/12 18:54, Prasad, Ramit wrote: data= [] for index in range(N, 1): # see Chris Rebert's comment with open('data%d.txt' % index,'r') as f: data.append( f.readlines() ) I think "dat

Re: Compare 2 times

2012-06-06 Thread Jon Clements
On 06/06/12 14:39, Christian Heimes wrote: Am 06.06.2012 14:50, schrieb loial: I have a requirement to test the creation time of a file with the current time and raise a message if the file is more than 15 minutes old. Platform is Unix. I have looked at using os.path.getctime for the file cre

Re: Is that safe to use ramdom.random() for key to encrypt?

2012-06-16 Thread Jon Clements
On Sun, 17 Jun 2012 12:31:04 +1000, Chris Angelico wrote: > On Sun, Jun 17, 2012 at 12:15 PM, Yesterday Paid > wrote: >> I'm making cipher program with random.seed(), random.random() as the >> key table of encryption. >> I'm not good at security things and don't know much about the algorithm >> u

Re: Is that safe to use ramdom.random() for key to encrypt?

2012-06-17 Thread Jon Clements
On Sun, 17 Jun 2012 23:17:37 +, Steven D'Aprano wrote: > On Mon, 18 Jun 2012 08:41:57 +1000, Chris Angelico wrote: > >> On Mon, Jun 18, 2012 at 3:06 AM, Rafael Durán Castañeda >> wrote: >>> The language Python includes a SystemRandom class that obtains >>> cryptographic grade random bits fro

Re: How does this work?

2011-06-04 Thread Jon Clements
On Jun 5, 4:37 am, Ben Finney wrote: > writes: > > I was surfing around looking for a way to split a list into equal > > sections. I came upon this algorithm: > > > >>> f = lambda x, n, acc=[]: f(x[n:], n, acc+[(x[:n])]) if x else acc > > >>> f("Hallo Welt", 3) > > ['Hal', 'lo ', 'Wel', 't'] > >

Re: Need help with simple OOP Python question

2011-09-05 Thread Jon Clements
On Sep 5, 3:43 pm, Peter Otten <__pete...@web.de> wrote: > Kristofer Tengström wrote: > > Thanks everyone, moving the declaration to the class's __init__ method > > did the trick. Now there's just one little problem left. I'm trying to > > create a list that holds the parents for each instance in t

Re: pattern matching

2011-02-24 Thread Jon Clements
On Feb 24, 2:11 am, monkeys paw wrote: > if I have a string such as '01/12/2011' and i want > to reformat it as '20110112', how do i pull out the components > of the string and reformat them into a DDMM format? > > I have: > > import re > > test = re.compile('\d\d\/') > f = open('test.html')  

Re: TextWrangler "run" command not working properly

2011-04-14 Thread Jon Clements
On Apr 14, 9:52 pm, Fabio wrote: > Hi to all, > I have troubles with TextWrangler "run" command in the "shebang" (#!) > menu. > I am on MacOSX 10.6.7. > I have the "built-in" Python2.5 which comes installed by "mother Apple". > Then I installed Python2.6, and left 2.5 untouched (I was suggested to

Re: Finding empty columns. Is there a faster way?

2011-04-21 Thread Jon Clements
On Apr 21, 5:40 pm, nn wrote: > time head -100 myfile  >/dev/null > > real    0m4.57s > user    0m3.81s > sys     0m0.74s > > time ./repnullsalt.py '|' myfile > 0 1 Null columns: > 11, 20, 21, 22, 23, 24, 25, 26, 27, 30, 31, 33, 45, 50, 68 > > real    1m28.94s > user    1m28.11s > sys     0m0.

Re: checking if a list is empty

2011-05-06 Thread Jon Clements
On May 7, 12:51 am, Ian Kelly wrote: > On Fri, May 6, 2011 at 4:21 PM, Philip Semanchuk wrote: > > What if it's not a list but a tuple or a numpy array? Often I just want to > > iterate through an element's items and I don't care if it's a list, set, > > etc. For instance, given this function d

Re: Wrote a new library - Comments and suggestions please!

2011-09-26 Thread Jon Clements
On Sep 26, 12:23 pm, Tal Einat wrote: > The library is called RunningCalcs and is useful for running several > calculations on a single iterable of values. > > https://bitbucket.org/taleinat/runningcalcs/http://pypi.python.org/pypi/RunningCalcs/ > > I'd like some input on how this could be made mo

Re: Wrote a new library - Comments and suggestions please!

2011-09-27 Thread Jon Clements
On Sep 27, 6:33 pm, Steven D'Aprano wrote: > Robert Kern wrote: > > On 9/27/11 10:24 AM, Tal Einat wrote: > >> I don't work with SAS so I have no reason to invest any time developing > >> for it. > > >> Also, as far as I can tell, SAS is far from free or open-source, meaning > >> I definitely am n

Re: Simplest way to resize an image-like array

2011-09-30 Thread Jon Clements
On Sep 30, 5:40 pm, John Ladasky wrote: > Hi folks, > > I have 500 x 500 arrays of floats, representing 2D "grayscale" images, > that I need to resample at a lower spatial resolution, say, 120 x 120 > (details to follow, if you feel they are relevant). > > I've got the numpy, and scipy, and matplo

Re: Usefulness of the "not in" operator

2011-10-08 Thread Jon Clements
On Oct 8, 11:42 am, candide wrote: > Python provides > >      -- the not operator, meaning logical negation >      -- the in operator, meaning membership > > On the other hand, Python provides the not in operator meaning > non-membership. However, it seems we can reformulate any "not in" > express

Re: Reading a file into a data structure....

2011-10-13 Thread Jon Clements
On Oct 13, 10:59 pm, MrPink wrote: > This is a continuing to a post I made in > August:http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > I got some free time to work with Python again and have some followup > questions. > > For example, I have a list in a text file like

Re: Looking for browser emulator

2011-10-13 Thread Jon Clements
On Oct 14, 3:19 am, Roy Smith wrote: > I've got to write some tests in python which simulate getting a page of > HTML from an http server, finding a link, clicking on it, and then > examining the HTML on the next page to make sure it has certain features. > > I can use urllib to do the basic fetch

Re: Looking for browser emulator

2011-10-13 Thread Jon Clements
On Oct 14, 3:19 am, Roy Smith wrote: > I've got to write some tests in python which simulate getting a page of > HTML from an http server, finding a link, clicking on it, and then > examining the HTML on the next page to make sure it has certain features. > > I can use urllib to do the basic fetch

Re: Loop through a dict changing keys

2011-10-16 Thread Jon Clements
On Oct 16, 12:53 am, PoD wrote: > On Sat, 15 Oct 2011 11:00:17 -0700, Gnarlodious wrote: > > What is the best way (Python 3) to loop through dict keys, examine the > > string, change them if needed, and save the changes to the same dict? > > > So for input like this: > > {'Mobile': 'string', 'cont

Re: understand program used to create file

2011-11-01 Thread Jon Clements
On Nov 1, 7:27 pm, pacopyc wrote: > Hi, I have about 1 files .doc and I want know the program used to > create them: writer? word? abiword? else? I'd like develop a script > python to do this. Is there a module to do it? Can you help me? > > Thanks My suggestion would be the same as DaveA's.

Re: simple file flow question with csv.reader

2011-11-02 Thread Jon Clements
On Nov 2, 11:50 pm, Terry Reedy wrote: > On 11/2/2011 7:06 PM, Dennis Lee Bieber wrote: > > > On Wed, 2 Nov 2011 14:13:34 -0700 (PDT), Matt > > declaimed the following in gmane.comp.python.general: > > >> I have a few hundred .csv files, and to each file, I want to > >> manipulate the data, then s

Re: Get keys from a dicionary

2011-11-11 Thread Jon Clements
On Nov 11, 1:31 pm, macm wrote: > Hi Folks > > I pass a nested dictionary to a function. > > def Dicty( dict[k1][k2] ): >         print k1 >         print k2 > > There is a fast way (trick) to get k1 and k2 as string. > > Whithout loop all dict. Just it! > > Regards > > macm I've tried to underst

Re: my new project, is this the right way?

2011-11-14 Thread Jon Clements
On Nov 14, 10:41 am, Tracubik wrote: > Hi all, > i'm developing a new program. > Mission: learn a bit of database management > Idea: create a simple, 1 window program that show me a db of movies i've > seen with few (<10) fields (actors, name, year etc) > technologies i'll use: python + gtk > db:

Re: Py2.7/FreeBSD: maximum number of open files

2011-11-14 Thread Jon Clements
On Nov 14, 5:03 pm, Tobias Oberstein wrote: > > > I need 50k sockets + 100 files. > > > > Thus, this is even more strange: the Python (a Twisted service) will > > > happily accept 50k sockets, but as soon as you do open() a file, it'll > > > bail out. > > > A limit of 32k smells like a overflow i

Re: can some one help me with my code. thanks

2012-01-20 Thread Jon Clements
On Jan 20, 9:26 pm, Terry Reedy wrote: > On 1/20/2012 2:46 PM, Terry Reedy wrote: > > > > > > > > > > > On 1/20/2012 1:49 PM, Tamanna Sultana wrote: > > >> can some one help me?? > >>> I would like to create a function that, given a bin, which is a list > >>> (example below), generates averages fo

Automatic email checking - best procedures/suggestions

2006-07-27 Thread Jon Clements
Hi All, I'm hoping someone has some experience in this field and could give me a pointer in the right direction - it's not purely python related though. Any modules/links someone has tried and found useful would be greatly appreciated... I want to have an automated process which basically has its

Re: How do you implement this Python idiom in C++

2006-07-27 Thread Jon Clements
[EMAIL PROTECTED] wrote: > // Curious class definitions > class CountedClass : public Counted {}; > class CountedClass2 : public Counted {}; > > It apparently works but in fact it doesn't: > If you derive from such a class, you get the count of the parent class, > > not of the derived class. > cla

Re: How do you implement this Python idiom in C++

2006-07-27 Thread Jon Clements
[EMAIL PROTECTED] wrote: > You miss the point; i want to derive a class and inherit all properties > without worrying about those implementation details. The Python code is > much cleaner in that respect. My post is about whether it is possible > to get such a clean interface in C++ I was simply

Re: Pickling an instance of a class containing a dict doesn't work

2006-10-12 Thread Jon Clements
Marco Lierfeld wrote: > The class looks like this: > class subproject: > configuration = {} > build_steps = [] > # some functions > # ... > > Now I create an instance of this class, e.g. > test = subproject() >

Re: Pickling an instance of a class containing a dict doesn't work

2006-10-12 Thread Jon Clements
Jon Clements wrote: > if you change the above to: > > class subproject: > def __init__(self): > configuration = { } > build_steps = [ ] Of course, I actually meant to write self.configuration and self.build_steps; d0h! -- http://mail.python.org/mailman/listinfo/python-list

Re: Loops Control with Python

2006-10-13 Thread Jon Clements
Wijaya Edward wrote: > Can we make loops control in Python? > What I mean is that whether we can control > which loops to exit/skip at the given scope. > > For example in Perl we can do something like: > > OUT: > foreach my $s1 ( 0 ...100) { > > IN: > foreach my $s2 (@array) { > >

Re: jython and toString

2006-10-16 Thread Jon Clements
ivansh wrote: > Hello, > > For one java class (Hello) i use another (HelloPrinter) to build the > string representation of the first one. When i've tried to use this > from within jython, HelloPrinter.toString(hello) call gives results > like Object.toString() of hello has being called. The exam

Re: making a valid file name...

2006-10-17 Thread Jon Clements
SpreadTooThin wrote: > Hi I'm writing a python script that creates directories from user > input. > Sometimes the user inputs characters that aren't valid characters for a > file or directory name. > Here are the characters that I consider to be valid characters... > > valid = > ':./,^0123456789a

Re: list comprehension (searching for onliners)

2006-10-20 Thread Jon Clements
Gerardo Herzig wrote: > Hi all: I have this list thing as a result of a db.query: (short version) > result = [{'service_id' : 1, 'value': 10}, > {'service_id': 2, 'value': 5}, > {'service_id': 1, 'value': 15}, > {'service_id': 2, 'value': 15}, >

Re: why does this unpacking work

2006-10-20 Thread Jon Clements
John Salerno wrote: > I'm a little confused, but I'm sure this is something trivial. I'm > confused about why this works: > > >>> t = (('hello', 'goodbye'), > ('more', 'less'), > ('something', 'nothing'), > ('good', 'bad')) > >>> t > (('hello', 'goodbye'), ('more', 'less'), ('

Re: curious paramstyle qmark behavior

2006-10-20 Thread Jon Clements
BartlebyScrivener wrote: > With > > aColumn = "Topics.Topic1"' > > The first statement "works" in the sense that it finds a number of > matching rows. > > c.execute ("SELECT Author, Quote, ID, Topics.Topic1, Topic2 FROM > QUOTES7 WHERE " + aColumn + " LIKE ?", ("%" + sys.argv[1] + "%",)) > > I've

Re: curious paramstyle qmark behavior

2006-10-21 Thread Jon Clements
BartlebyScrivener wrote: > Thanks, Jon. > > I'm moving from Access to MySQL. I can query all I want using Python, > but so far haven't found a nifty set of forms (ala Access) for easying > entering of data into MySQL. My Python is still amateur level and I'm > not ready for Tkinkter or gui progr

Re: curious paramstyle qmark behavior

2006-10-21 Thread Jon Clements
BartlebyScrivener wrote: > Jon Clements wrote: > > > if your load on the data-entry/browsing side isn't too heavy, you can > > use the 'development server' instead of installing a full-blown server > > such as Apache (I'm not sure if IIS is supported)

Re: can't open word document after string replacements

2006-10-24 Thread Jon Clements
Antoine De Groote wrote: > Hi there, > > I have a word document containing pictures and text. This documents > holds several 'ABCDEF' strings which serve as a placeholder for names. > Now I want to replace these occurences with names in a list (members). I > open both input and output file in bin

Re: Ctypes Error: Why can't it find the DLL.

2006-10-25 Thread Jon Clements
Mudcat wrote: > So then I use the find_library function, and it finds it: > > >>> find_library('arapi51.dll') > 'C:\\WINNT\\system32\\arapi51.dll' > Notice it's escaped the '\' character. > At that point I try to use the LoadLibrary function, but it still can't > find it: > > >>> windll.LoadLi

Re: dict problem

2006-10-25 Thread Jon Clements
Alistair King wrote: > Hi, > > ive been trying to update a dictionary containing a molecular formula, but > seem to be getting this error: > > > Traceback (most recent call last): > File "DS1excessH2O.py", line 242, in ? > updateDS1v(FCas, C, XDS) > NameError: name 'C' is not defined > > d

Re: dict problem

2006-10-25 Thread Jon Clements
Alistair King wrote: > Jon Clements wrote: > > > > Alistair King wrote: > > > > > > > > > >> >> Hi, > >> >> > >> >> ive been trying to update a dictionary containing a molecular formula, > >> &

Re: newbie class-building question

2006-11-09 Thread Jon Clements
jrpfinch wrote: > I am constructing a simple class to make sure I understand how classes > work in Python (see below this paragraph). > > It works as expected, except the __add__ redefinition. I get the > following in the Python interpreter: > > >>> a=myListSub() > >>> a > [] > >>> a+[5] > Trace

Re: newbie class-building question

2006-11-09 Thread Jon Clements
jrpfinch wrote: > Thank you this is very helpful. The only thing I now don't understand > is why it is calling __coerce__. self.wrapped and other are both > lists. Yes, but in "a + [5]", *a* is a myListSub object -- it's not a list! So __coerce__ is called to try and get a common type... Try

Re: extract text from a string

2006-11-09 Thread Jon Clements
[EMAIL PROTECTED] wrote: > Hallo all, > > I have tried for a couple of hours to solve my problem with re but I > have no success. > > I have a string containing: "+abc_cde.fgh_jkl\n" and what I need to > become is "abc_cde.fgh_jkl". Could anybody be so kind and write me a > code of how to extrac

Re: generating random passwords ... for a csv file with user details

2006-05-28 Thread Jon Clements
Something like: import csv in_csv=csv.reader( file('your INPUT filenamehere.csv') ) out_csv=csv.writer( file('your OUPUT filenamehere.csv','wb') ) ## If you have a header record on your input file, then out_csv.writerow( in_csv.next() ) ## Iterate over your input file for row in in_csv: # Row

Re: Using print instead of file.write(str)

2006-06-01 Thread Jon Clements
Didn't know of the >> syntax: lovely to know about it Bruno - thank you. To the OP - I find the print statement useful for something like: print 'this','is','a','test' >>> 'this is a test' (with implicit newline and implicit spacing between parameters) If you want more control (more flexibility,

Re: Using print instead of file.write(str)

2006-06-01 Thread Jon Clements
I meant 'trailing': not leading. mea culpa. Jon. Jon Clements wrote: > Didn't know of the >> syntax: lovely to know about it Bruno - thank > you. > > To the OP - I find the print statement useful for something like: > print 'this','is',&#

Re: How to generate k+1 length strings from a list of k length strings?

2006-06-08 Thread Jon Clements
Are you asking the question, "Which pairs of strings have one character different in each?", or "Which pairs of strings have a substring of len(string) - 1 in common?". Jon. Girish Sahani wrote: > I have a list of strings all of length k. For every pair of k length > strings which have k-1 charac

Re: "groupby" is brilliant!

2006-06-13 Thread Jon Clements
Not related to itertools.groupby, but the csv.reader object... If for some reason you have malformed CSV files, with embedded newlines or something of that effect, it will raise an exception. To skip those, you will need a construct of something like this: raw_csv_in = file('filenamehere.csv') fo

Re: __cmp__ method

2006-06-14 Thread Jon Clements
This probably isn't exactly what you want, but, unless you wanted to do something especially with your own string class, I would just pass a function to the sorted algorithm. eg: sorted( [a,b,c], cmp=lambda a,b: cmp(len(a),len(b)) ) gives you the below in the right order... Never tried doing wh

Re: Iteration over recursion?

2006-06-20 Thread Jon Clements
MTD wrote: > Hello all, > (snip) > I've been told that iteration in python is generally more > time-efficient than recursion. Is that true? (snip) AFAIK, in most languages it's a memory thing. Each time a function calls itself, the 'state' of that function has to be stored somewhere so that it

Re: Iteration over recursion?

2006-06-20 Thread Jon Clements
Sudden Disruption wrote: > Bruno, > > > It doesn't. Technical possible, but BDFL's decision... > > Sure. But why bother? > I agree. > Anything that can be done with recursion can be done with iteration. > Turng proved that in 1936. > > Recursion was just an attempt to "unify" design approach b

Re: Iteration over recursion?

2006-06-20 Thread Jon Clements
Kay Schluehr wrote: > Nick Maclaren wrote: > > > Tail recursion removal can often eliminate the memory drain, but the > > code has to be written so that will work - and I don't know offhand > > whether Python does it. > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691 > > Regards

Re: error with string (beginner)

2006-06-25 Thread Jon Clements
Alex Pavluck wrote: > Hello. I get the following error with the following code. Is there > something wrong with my Python installation? > > code: > import types > something = input("Enter something and I will tell you the type: ") > > if type(something) is types.IntType: > print "you entered

Extending built-in objects/classes

2006-07-03 Thread Jon Clements
Hi All, I've reached the point in using Python where projects, instead of being like 'batch scripts', are becoming more like 'proper' programs. Therefore, I'm re-designing most of these and have found things in common which I can use classes for. As I'm only just starting to get into classes, I s

Re: Extending built-in objects/classes

2006-07-03 Thread Jon Clements
[EMAIL PROTECTED] wrote: > My experiance is mostly with old-style classes, but here goes. > > first off, the question is actually easier than you think. > After all, self is an instance of a string, so self[3:4] would grab > the slice of characters between 3 and 4 =) > That's kind of funky - I

Re: Extending built-in objects/classes

2006-07-03 Thread Jon Clements
John Machin wrote: (snip) > > You have already been told: you don't need "self.", you just write > "self" ... self *is* a reference to the instance of the mystr class that > is being operated on by the substr method. > (snip) I get that; let me clarify why I asked again. As far as I'm aware, the

Re: IRC questions!!

2006-07-07 Thread Jon Clements
bruce wrote: > hi... > > i'm trying to figure out what i have to do to setup mIRC to get the #python > channel on IRC!! > > any pointers. the mIRC docs didn't get me very far. > > is there an irc.freenode.net that i need to connect to? how do i do it? > > thanks.. > > -bruce Assuming you're famil

Re: Simple question on indexing

2006-12-01 Thread Jon Clements
Tartifola wrote: > Hi, > I would like to obtain the position index in a tuple when an IF > statement is true. Something like > > >>>a=['aaa','bbb','ccc'] > >>>[ ??? for name in a if name == 'bbb'] > >>>1 > > but I'm not able to find the name of the function ??? in the python > documentation, any

Re: route planning

2006-12-01 Thread Jon Clements
It's not really what you're after, but I hope it might give some ideas (useful or not, I don't know). How about considering a vertex as a point in space (most libraries will allow you to decorate a vertex with additonal information), then creating an edge between vertices, which will be your 'path

Re: How to replace a comma

2006-12-18 Thread Jon Clements
Lad wrote: > In a text I need to > add a blank(space) after a comma but only if there was no blank(space) > after the comman > If there was a blank(space), no change is made. > > I think it could be a task for regular expression but can not figure > out the correct regular expression. > Can anyon

Re: Encoding / decoding strings

2007-01-05 Thread Jon Clements
[EMAIL PROTECTED] wrote: > Hey Everyone, > > Was just wondering if anyone here could help me. I want to encode (and > subsequently decode) email addresses to use in URLs. I believe that > this can be done using MD5. > > I can find documentation for encoding the strings, but not decoding > them. W

Re: Writing a nice formatted csv file

2007-05-02 Thread Jon Clements
On 2 May, 15:14, redcic <[EMAIL PROTECTED]> wrote: > Hi all, > > I use the csv module of Python to write a file. My code is of the > form : > > cw = csv.writer(open("out.txt", "wb")) > cw.writerow([1,2,3]) > cw.writerow([10,20,30]) > > And i get an out.txt file looking like: > 1,2,3 > 10,20,30 > >

  1   2   3   >