On Apr 10, 9:52 pm, Michael Torrie wrote:
> On 04/10/2013 07:21 PM, gry wrote:
>
>
>
>
>
>
>
>
>
> > from sys import stdout
> > from array import array
> > import random
> > nchars = 3200
> > rows = 10
> > avail_chrs =
&
Dear pythonistas,
I am writing a tiny utility to produce a file consisting of a
specified number of lines of a given length of random ascii
characters. I am hoping to find a more time and memory efficient way,
that is still fairly simple clear, and _pythonic_.
I would like to have something th
sys.version --> '2.6 (r26:66714, Feb 21 2009, 02:16:04) \n[GCC 4.3.2
[gcc-4_3-branch revision 141291]]
I thought this script would be very lean and fast, but with a large
value for n (like 15), it uses 26G of virtural memory, and things
start to crumble.
#!/usr/bin/env python
'''write a file o
On Sep 9, 2:04 am, Terry Reedy wrote:
> On 9/8/2011 9:09 PM, papu wrote:
>
>
>
> > Hello, I have a data file (un-structed messy file) from which I have
> > to scrub specific list of words (delete words).
>
> > Here is what I am doing but with no result:
>
> > infile = "messy_data_file.txt"
> > out
On Sep 8, 3:51 pm, gry wrote:
To elaborate(always give example of desired output...) I would hope to
get something like:
SELECT public.max(PUBLIC.TT.I) AS SEL_0 FROM (SCHM.T RIGHT OUTER JOIN
PUBLIC.TT ON (SCHM.T.I IS NULL)) WHERE (NOT(NOT((power(PUBLIC.TT.F,
PUBLIC.TT.F) = cast(ceil
[Python 2.7]
I have a body of text (~1MB) that I need to modify. I need to look
for matches of a regular expression and replace a random selection of
those matches with a new string. There may be several matches on any
line, and a random selection of them should be replaced. The
probability of
[python 2.7] I have a (linux) pathname that I'd like to split
completely into a list of components, e.g.:
'/home/gyoung/hacks/pathhack/foo.py' --> ['home', 'gyoung',
'hacks', 'pathhack', 'foo.py']
os.path.split gives me a tuple of dirname,basename, but there's no
os.path.split_all function.
On Jan 4, 1:11 am, John Nagle wrote:
> On 1/1/2011 11:26 PM, azakai wrote:
>
> > Hello, I hope this will be interesting to people here: CPython running
> > on the web,
>
> >http://syntensity.com/static/python.html
>
> > That isn't a new implementation of Python, but rather CPython 2.7.1,
> > compi
[python-2.4.3, rh CentOS release 5.5 linux, 24 xeon cpu's, 24GB ram]
I have a little data generator that I'd like to go faster... any
suggestions?
maxint is usually 9223372036854775808(max 64bit int), but could
occasionally be 99.
width is usually 500 or 1600, rows ~ 5000.
from random import randi
> >>> s='555tHe-rain.in#=1234'
> >>> import re
> >>> r=re.compile(r'([a-zA-Z]+|\d+|.)')
> >>> r.findall(s)
> ['555', 'tHe', '-', 'rain', '.', 'in', '#', '=', '1234']
This is nice and simple and has the invertible property that Patrick
mentioned above. Thanks much!
--
http://mail.py
On Apr 8, 3:40 pm, MRAB wrote:
...
> Group 1 and group 4 match '='.
> Group 1 and group 3 match '1234'.
>
> If a group matches then any earlier match of that group is discarded,
Wow, that makes this much clearer! I wonder if this behaviour
shouldn't be mentioned in some form in the python docs?
[ python3.1.1, re.__version__='2.2.1' ]
I'm trying to use re to split a string into (any number of) pieces of
these kinds:
1) contiguous runs of letters
2) contiguous runs of digits
3) single other characters
e.g. 555tHe-rain.in#=1234 should give: [555, 'tHe', '-', 'rain',
'.', 'in', '#', '=
I want a function (or callable something) that returns a random
word meeting a criterion. I can do it like:
def random_richer_word(word):
'''find a word having a superset of the letters of "word"'''
if len(set(word) == 26): raise WordTooRichException, word
while True:
w = rand
Russ wrote:
> I have a python module (file) that has a set of parameters associated
> with it. Let's say the module is called "code.py." I would like to keep
> the parameter assignments in a separate file so that I can save a copy
> for each "run" without having to save the entire code.py file. Let
Kay Schluehr wrote:
> I have a list of strings ls = [s_1,s_2,...,s_n] and want to create a
> regular expression sx from it, such that sx.match(s) yields a SRE_Match
> object when s starts with an s_i for one i in [0,...,n]. There might
> be relations between those strings: s_k.startswith(s_1) ->
Alex Pavluck wrote:
> Hello. On page 124 of "Thinking like a Computer Scientist". There is
> an exercise to take the following code and with the use of TRY: /
> EXCEPT: handle the error. Can somone help me out? Here is the code:
>
> def inputNumber(n):
> if n == 17:
> raise 'BadNumb
Alex Pavluck wrote:
> Hello. On page 124 of "Thinking like a Computer Scientist". There is
> an exercise to take the following code and with the use of TRY: /
> EXCEPT: handle the error. Can somone help me out? Here is the code:
>
> def inputNumber(n):
> if n == 17:
> raise 'BadNumb
I agree. The "--version" option has become quite a de-facto standard
in the linux world. In my sys-admin role, I can blithely run
initiate_global_thermonuclear_war --version
to find what version we have, even if I don't know what it does...
python --version
would be a very helpful addition.
index is about the best you can do with the structure you're using.
If you made the "items" instances of a class, then you could define a
__cmp__ member, which would let you do:
a=Item('A')
b=Item('B')
if ahttp://mail.python.org/mailman/listinfo/python-list
A perspective that I haven't seen raised here is inheritance.
I often say
mylist = []
if I'm done with the current contents and just want a fresh list.
But the cases where I have really needed list.clear [and laboriously
looked for it and ended up with
del l[:]
were when the object was my o
Read about string split and join. E.g.:
l = '0.87 0.25 0.79'
floatlist = [float(s) for s in l.split()]
In the other direction:
floatlist = [0.87, 0.25, 0.79004]
outstring = ' '.join(floatlist)
If you need to control the precision(i.e. suppress the 4), read
about
the s
http://www.python.org/doc/topics/database/
--
http://mail.python.org/mailman/listinfo/python-list
For multiple keys the form is quite analogous:
L.sort(key=lambda i: (i.whatever, i.someother, i.anotherkey))
I.e., just return a tuple with the keys in order from your lambda.
Such tuples sort nicely.
-- George Young
--
http://mail.python.org/mailman/listinfo/python-list
This would indeed be a nice feature.
The glob module is only 75 lines of pure python. Perhaps you would
like
to enhance it? Take a look.
--
http://mail.python.org/mailman/listinfo/python-list
In fact, not just characters, but strings contain themselves:
>>> 'abc' in 'abc'
True
This is a very nice(i.e. clear and concise) shortcut for:
>>> 'the rain in spain stays mainly'.find('rain') != -1
True
Which I always found contorted and awkward.
Could you be a bit more concrete about your c
Martin P. Hellwig wrote:
> Hi all,
>
> I was doing some popen2 tests so that I'm more comfortable using it.
> I wrote a little python script to help me test that (testia.py):
>
> -
> someline = raw_input("something:")
>
> if someline == 'test':
> print("yup")
>
First, don't appologize for asking questions. You read, you thought,
and you tested. That's more than many people on this list do. Bravo!
One suggestion: when asking questions here it's a good idea to always
briefly mention which version of python and what platform (linux,
windows, etc) you're
Just curious about people's sense of style:
To delete all the elements of a list, should one do:
lst[:] = []
or
del(lst[:])
I seem to see the first form much more often in code, but
the second one seems more clearly *deleting* elements,
and less dangerously mistaken for the completely diff
[python 2.3.3, pyparsing 1.3]
I have:
def unpack_sql_array(s):
# unpack a postgres "array", e.g. "{'w1','w2','w3'}" into a
list(str)
import pyparsing as pp
withquotes = pp.dblQuotedString.setParseAction(pp.removeQuotes)
withoutquotes = pp.CharsNotIn('",{}')
parser = pp.StringS
Christoph Zwerschke wrote:
> Usually, you initialize class variables like that:
>
> class A:
> sum = 45
>
> But what is the proper way to initialize class variables if they are the
> result of some computation or processing as in the following silly
> example (representative for more:
>
> class
Just a few suggestions:
1) use consistant formatting, preferably something like:
http://www.python.org/peps/pep-0008.html
E.g.:
yesno = {0:"No", 1:"Yes", True:"Yes", False:"No"}
2) if (isinstance(self.random_seed,str)):
s=s+"Random Seed: %s\n" % self.random_seed
else:
NateM wrote:
> How do I convert any given date into a milliseconds value that
> represents the number of milliseconds that have passed since January 1,
> 1970 00:00:00.000 GMT?
> Is there an easy way to do this like Date in java?
> Thanks,
> Nate
The main module for dates and times is "datetime";
[EMAIL PROTECTED] wrote:
> Hello there,
> i need a way to check to see if a certain value can be an integer. I
> have looked at is int(), but what is comming out is a string that may
> be an integer. i mean, it will be formatted as a string, but i need to
> know if it is possible to be expressed as
John Reese wrote:
> Hi.
>
> >>> import time, calendar, datetime
> >>> n= 1133893540.874922
> >>> datetime.datetime.fromtimestamp(n)
> datetime.datetime(2005, 12, 6, 10, 25, 40, 874922)
> >>> lt= _
> >>> datetime.datetime.utcfromtimestamp(n)
> datetime.datetime(2005, 12, 6, 18, 25, 40, 874922)
> >>
There was just recently announced -- iplib-0.9:
http://groups.google.com/group/comp.lang.python.announce/browse_frm/thread/e289a42714213fb1/ec53921d1545bf69#ec53921d1545bf69
It appears to be pure python and has facilities for dealing with
netmasks. (v4 only).
-- George
--
http://mail.python.or
[EMAIL PROTECTED] wrote:
> Hello,
>
> I am considering using dictionnaries as lookup tables e.g.
>
> >>>D={0.5:3.9,1.5:4.2,6.5:3}
>
> and I would like to have a dictionnary method returning the key and
> item of the dictionnary whose key is smaller than the input of the
> method (or <=,>,>=) but m
import sys
for l in sys.stdin:
sys.stdout.write(l)
-- George
--
http://mail.python.org/mailman/listinfo/python-list
Yes, "eval" of data from a file is rather risky. Suppose someone gave
you
a file containing somewhere in the middle:
...
22,44,66,88,"asd,asd","23,43,55"
os.system('rm -rf *')
33,47,66,88,"bsd,bsd","23,99,88"
...
This would delete all the files in your directory!
The csv module mentioned above i
Linux -2.4.20 (x86), Python 2.3.3.
I did exactly as you suggested.
After the stderr.write, a window pops up with title "Error Stream from
run of errorwindow.pyc".
The window is otherwise blank.
Nothing more happens when I do the "x=7+nosuchvariable", I just get
the next python ">>>" prompt, but no
Python 2.3.3, Tkinter.__version__'$Revision: 1.177 $'
Hmm, the error window pops up with appropriate title, but contains no
text.
I stuck an unbuffered write to a log file in ErrorPipe.write and got
only one line: Traceback (most recent call last):$
Any idea what's wrong?
-- George
--
http://m
sysfault wrote:
> Hello, I have a function which takes a program name, and I'm using
> os.popen() to open that program via the syntax: os.popen('pidof var_name',
> 'r'), but as you know var_name is not expanded within single quotes, I
> tried using double quotes, and such, but no luck. I was lookin
What I have done in similar circumstances is put in a random sleep
between connections to fool the server's load manager. Something like:
.import time
.min_pause,max_pause = (5.0, 10.0) #seconds
.while True:
. time.sleep(random.uniform(min_pause, max_pause))
. do_connection_and_query_stuff()
Aditi wrote:
> hi all...i m a software engg. student completed my 2nd yr...i have been
> asked to make a project during these summer vacations...and hereby i
> would like to invite some ideas bout the design and implementation of
> an APPLICATION MONITORING SYSTEMi have to start from scrach so
PyParsing rocks! Here's what I ended up with:
def unpack_sql_array(s):
import pyparsing as pp
withquotes = pp.dblQuotedString.setParseAction(pp.removeQuotes)
withoutquotes = pp.CharsNotIn('",')
parser = pp.StringStart() + \
pp.Word('{').suppress() + \
pp.
I have a string like:
{'the','dog\'s','bite'}
or maybe:
{'the'}
or sometimes:
{}
[FYI: this is postgresql database "array" field output format]
which I'm trying to parse with the re module.
A single quoted string would, I think, be:
r"\{'([^']|\\')*'\}"
but how do I represent a *sequence* of
Hugh Macdonald wrote:
> We're starting to version a number of our python modules here, and
I've
> written a small function that assists with loading the versioned
> modules...
>
> A module would be called something like: myModule_1_0.py
>
> In anything that uses it, though, we want to be able to r
Hmm, I had no idea that "property" was a class. It's listed in the
library
reference manual under builtin-functions. That will certainly make
things neater. Thanks!
-- George
--
http://mail.python.org/mailman/listinfo/python-list
I often find myself wanting an instance attribute that can take on only
a few fixed symbolic values. (This is less functionality than an enum,
since there are no *numbers* associated with the values). I do want
the thing to fiercely object to assignments or comparisons with
inappropriate values.
I sometimes use the implicit literal string concatenation:
def SomeFunction():
if SomeCondition:
MyString = 'The quick brown fox ' \
'jumped over the ' \
'lazy dog'
print MyString
SomeFunction()
The quick brown fox jumped over the lazy dog
It loo
<[EMAIL PROTECTED]> wrote:
> I am new to python and I am not in computer science. In fact I am a
biologist and I ma trying to learn python. So if someone can help me, I
will appreciate it.
> Thanks
>
>
> #!/cbi/prg/python/current/bin/python
> # -*- coding: iso-8859-1 -*-
> import sys
> import os
>
SPJ wrote:
> I am new to python hence posing this question.
> I have a file with the following format:
>
> test11.1-1 installed
> test11.1-1 update
> test22.1-1 installed
> test22.1-2 update
>
> I want the file to be formatted in the following way:
>
> test11.1-1 1.1-2
As far as I can tell, what you ultimately want is to be able to extract
a random ("representative?") subset of sentences. Given the huge size
of data, I would suggest not randomizing the file, but randomizing
accesses to the file. E.g. (sorry for off-the-cuff pseudo python):
[adjust 8196 == 2**13
[your "%b" is supposed to be the abbreviated month name, not the
number. Try "%m"]
In [19]: datetime.datetime(*time.strptime("20-3-2005","%d-%m-%Y")[:6])
Out[19]: datetime.datetime(2005, 3, 20, 0, 0)
Cheers,
George
--
http://mail.python.org/mailman/listinfo/python-list
To inherit from an immutable class, like string or tuple, you need to
use the __new__ member, not __init__. See, e.g.:
http://www.python.org/2.2.3/descrintro.html#__new__
--
http://mail.python.org/mailman/listinfo/python-list
Premshree Pillai wrote:
> PyAC 0.1.0 (http://sourceforge.net/projects/pyac/)
>
> * ignores non-image files
> * optional arg is_ppt for ordering presentation images (eg.,
> Powerpoint files exported as images)
> * misc fixes
>
> Package here:
http://sourceforge.net/project/showfiles.php?group_id=10
import pg
db = pg.DB('bind9', '192.168.192.2', 5432, None, None, 'named', None)
db.query('create temp table fffz(i int,t text)')
db.query('copy fffz from stdin')
db.putline("3\t'the'")
db.putline("4\t'rain'")
db.endcopy()
db.query('commit')
Note that multiple columns must be separated by tabs ('\t
The _winreg api looks helpful; unfortunately, I'm trying to stick to
what can be got
from the cygwin install -- no _winreg. Simplicity of installation is
quite important.
(I'm using cygwin to get the xfree86 X-server, which is the whole point
of this exercise)
I have found the cygwin command-line
[Windows XP Pro, cygwin python 2.4, *nix hacker, windows newbie]
I want to write some kind of install script for my python app that
will add c:\cygwin\usr\bin to the system path. I don't want
to walk around to 50 PC's and twiddle through the GUI to:
My Computer --> Control Panel --> System --> A
[Windows XP Pro, cygwin python 2.4]
Under cygwin, the python executable is installed as python2.4.exe with
a
symbolic link to python.exe. This is fine as long as one is operating
only
withing the cygwin world. But I execute python from a foo.bat file,
and
windows barfs on the symbolic link. I r
59 matches
Mail list logo