Hi,
In the attached code, I'm trying to pickle and unpickle
(1) an object containing a list of dictionaries.
(2) an object containing a list objects each containing a dictionary.
Case (1) seems to work (printing succesfully),
-
Running '/home/johan/prog/ratings/testpickle2.py' ...
{'tel': 1234,
Hi everybody,
I have a data packet in Hex values and need to determine how to calculate the CRC-16 bit checksum for these values.
Eg.:
0x55,0x00,0x0A,0x01,0x01, 0x01,0xFF,0x00,0xDC,0xCC
Sync| Lenght |source addr|dest. adr |Data| CRC check|
This example shows me the CRC chechsum, but if I ch
map(None, North, South, East West) does exactly what you want:
>>> North=['Bill', 'Bob', 'Sue', 'Mary']
>>> South=['Tim', 'Tom', 'Jim', 'John', 'Carl', 'Evan', 'Rich']
>>> map(None, North, South)
[('Bill', 'Tim'), ('Bob', 'Tom'), ('Sue', 'Jim'), ('Mary', 'John'), (None,
'Carl'), (None, 'Evan
Tony Cappellini wrote:
I havne't seen Kent's reply yet- will have to look when I get home from
work.
But I 've found some inconsistnacies with map, depending on which order
the args were passed in.
If the shorter list was passed to map first, as in map(shortlist,
longerlist), it behaved one way.
Th
Alan Gauld wrote:
As an aside, I did try to create a lambda based solution but was
unable. Let me know what's wrong:
ftable = { 'a' : lambda: print 'a',
SyntaxError: invalid syntax
I did say "if Python had *proper* lambdas..."
Unfortunately Python insists on only having *expressions* as
lambdas an
LOL
> Here's one, just for your amusement:
>
> But getting back on topic: I like Kent's solution with map() much better
> than my own. I had completely forgotten that map() had a special case
> that applies directly to what you're trying to do.
I havne't seen Kent's reply yet- will have to look
I aplogise for a typo...
Please read the command as:
cat log|grep -v -E [[:alnum]]'{2096,}'>> log.bak
note the missing comma in the previous command.
--- Shitiz Bansal <[EMAIL PROTECTED]> wrote:
>
> How about
>cat log|grep -v -E [[:alnum]]'{2096}'>> log.bak
>
> The issue is - will un
Alan Gauld wrote:
>ie No lambda used at all.
>
>I wish Python had real lambdas!
>
>
If python had real lambda's then it would be lisp or schema.
__
Do you Yahoo!?
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.co
> without the explicit newlines in file.write(i), could it be that the
> file was closed before the write buffer was ever flushed?
No because close() was called explicitly, which does a flush first...
Alan G.
___
Tutor maillist - Tutor@python.org
h
> How about
>cat log|grep -v -E [[:alnum]]'{2096}'>> log.bak
OK< but you can miss the cat out
grep -v -E [[:alnum]]'{2096}' log >> log.bak
But I confess I've no idea how that works, I've never
seen that notation in a grep before! Checking man reveals
an "extended regex" which I interpret
I have two questions. Once a MxN world is generated how would you
search for nearest neighbors (to see who is connected) and then color
Does this help?
import random
PERSON, EMPTY = '*', '.'
def get_threshold():
perc = raw_input("Please enter a thresold between 0-1. ")
perc = float(perc)
That's actually worse than you might think. Try this:
> def p(): pass
> ftable = { 'a' : lambda: 'a',
> 'd' : lambda: p}
That should be:
'd': p}
ie No lambda used at all.
I wish Python had real lambdas!
> And what you get is:
>
Yep, coz the lambda returns a function ob
Reed L. O'Brien wrote:
I want to read the httpd-access.log and remove any oversized log records
I quickly tossed this script together. I manually mv-ed log to log.bak
and touched a new logfile.
running the following with print i uncommented does print each line to
stdout. but it doesn't write
On Mon, 7 Feb 2005, Viktor Hornak wrote:
> I've been trying to find more resources/documentation about how to
> convert python lists to C arrays (and vice versa) when writing a python
> extension.
Hi Viktor,
There was a post back in 1999 that might be useful for you:
http://mail.python.o
without the explicit newlines in file.write(i), could it be that the
file was closed before the write buffer was ever flushed?
mike
On Mon, 7 Feb 2005 14:58:03 -0500, Smith, Jeff <[EMAIL PROTECTED]> wrote:
> -Original Message-
> From: Alan Gauld [mailto:[EMAIL PROTECTED]
> Sent: Monday,
On Mon, Feb 07, 2005 at 01:01:29PM -0800, Shitiz Bansal wrote:
>
> How about
>cat log|grep -v -E [[:alnum]]'{2096}'>> log.bak
UUOC (Useless Use Of Cat)
SCNR
J"o!
--
You're at the end of the road again.
___
Tutor maillist - Tutor@python.org
htt
Liam Clarke wrote:
oh? Is is the negative?
No, the decimal fraction. It's easy enough to try it:
>>> int('950')
950
>>> int('-950')
-950
>>> int('950.00')
Traceback (most recent call last):
File "", line 1, in ?
ValueError: invalid literal for int(): 950.00
>>> int('-950.00')
Traceback (most
oh? Is is the negative?
On Mon, 07 Feb 2005 09:36:02 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Liam Clarke wrote:
> >>>example of (1):
> >>>-
> >>>#this part of the program reads the file basin.out (the data we want to
> >>>analyze) a
How about
cat log|grep -v -E [[:alnum]]'{2096}'>> log.bak
The issue is - will unix shell command be any more
efficient than a python script??
Also i used append because i gathered that the user
will not want to erase the previous logs. He is free
to use a single > if he does.
--- Alan Gaul
Hi Chandu,
Ah, so you're looking into "environmental acquisition". I think the
reason you're asking about on Tutor is because one of the most visible
deployments of acquisition has been in the Zope web framework.
But just because Zope is written in Python doesn't mean that acquisition
is a conc
On Mon, 7 Feb 2005, Tony Cappellini wrote:
> > Here's a quick function that should force a certain length on an
> > iterator:
> >
> > ###
> > def ipad(iterable, length, sentinel=None):
> > i = 0
> > for thing in iterable:
> > yield thing
> > i = i + 1
> > while i < le
Alan,
That's actually worse than you might think. Try this:
var = 'd'
def p(): pass
ftable = { 'a' : lambda: 'a',
'b' : lambda: 'b or c',
'c' : lambda: 'b or c',
'd' : lambda: p}
print ftable.get(var, lambda: 'default case')()
And what you get is:
That's hard
> Well you can use lambdas. Have them return an expression which you
print
> after retrieving:
> ftable = { 'a' : lambda: 'a',
> 'b' : lambda: 'b or c',
> But it would be clearer to store just the expressions:
> ftable = { 'a' : 'a',
> 'b' : 'b or c',
True for this speci
> That's kinda what I thought but a couple of people suggested
> that I used lambdas to make it clearer
I suggested that if we had proper lambdas we could use 'em...
But of course you can still use lambdas just put the print
at the client side:
def p(): pass
ftable = { 'a' : lambda: 'a',
-Original Message-
From: Alan Gauld [mailto:[EMAIL PROTECTED]
Sent: Monday, February 07, 2005 2:49 PM
To: Reed L. O'Brien; tutor@python.org
Subject: Re: [Tutor] manipulating a file
>You should add a newline character otherwise you will just
>get one enormously long line!
>
>
> How about using a try loop every time you read from
> the list.
try is not a loop.
> try:
>x=list[someno]
> except:
>x=nothing(or whatever)
>
> This goes on till the all lists start returning none.
No, sorry it just does it once.
try/except is for detecting errors not a looping constr
> About the efficiency, why do u need python at all...
> How abt a simple shell command
>cat httpd-access.log>>log.bak
>
Because that would be a copy, well actually an append...
cp httpd-access.log log.bak
would be better!
But the OP wanted to strip out long lines in transit
not ju
> running the following with print i uncommented does print each line
to
> stdout. but it doesn't write to the appropriate file...
Does it do anything?
BTW YOu don;t need to touch a file, the 'w' parameter will
create a new file if one doesn't exist.
> c) I originally wanted to delete lines over
> As an aside, I did try to create a lambda based solution but was
unable.
> Let me know what's wrong:
>
> ftable = { 'a' : lambda: print 'a',
> SyntaxError: invalid syntax
I did say "if Python had *proper* lambdas..."
Unfortunately Python insists on only having *expressions* as
lambdas and since
> Out of curiosity, if it's not possible to run zip() directly on the lists
> that you have, can you bend the lists so that zip() will fit?
It is possible, however zip() truncates the longer list, based on the size
of the smaller list, so it's just not feasible in my case.
> Here's a quick functi
[Reposting. Didnt make it the first time - Sandip]
Forwarded Message
From: Sandip Bhattacharya <[EMAIL PROTECTED]>
To: Python Tutor Mailing List
Subject: want recommendations for interfacing with postgresql
Date: Mon, 07 Feb 2005 20:39:27 +0530
Hi!
I am planning to work with pos
Hi!
I am planning to work with postgresql and python for one of my projects.
Which library module would you recommend for the job?
I have seen:
1. http://www.pygresql.org (pgdb module)
2. http://initd.org/projects/psycopg1
Thanks,
Sandip
--
Sandip Bhattacharya*Puroga Technologies *
Bob Gailer wrote:
At 07:14 AM 2/7/2005, Smith, Jeff wrote:
Alan,
No use beating this dead horse...I guess that's why there are so many
languages in the first place. Different people are comfortable with
different things. (I did warn you that I like both Lisp and Prolog and
only wish I had more of
Bob,
Unfortunately, that doesn't do the same thing. In the 'd' case, you get
a print rather than a pass for instance. It was also just happenstance
that I chose to print on each switch rather than do something like
increment a counter.
Jeff
-Original Message-
From: Bob Gailer [mailto:[
At 07:43 AM 2/7/2005, Smith, Jeff wrote:
That's kinda what I thought but a couple of people suggested that I used
lambdas to make it clearer that I figured I was doing something wrong...
Well you can use lambdas. Have them return an expression which you print
after retrieving:
ftable = { 'a' : lam
That's kinda what I thought but a couple of people suggested that I used
lambdas to make it clearer that I figured I was doing something wrong...
Jeff
-Original Message-
From: Bob Gailer [mailto:[EMAIL PROTECTED]
Sent: Monday, February 07, 2005 9:48 AM
To: Smith, Jeff; tutor@python.org
S
At 07:14 AM 2/7/2005, Smith, Jeff wrote:
Alan,
No use beating this dead horse...I guess that's why there are so many
languages in the first place. Different people are comfortable with
different things. (I did warn you that I like both Lisp and Prolog and
only wish I had more of a reason to use t
Liam Clarke wrote:
example of (1):
-
#this part of the program reads the file basin.out (the data we want to
analyze) and changes its contents to the array arr_xy
#layout of basin.out:
#1 -950.0010.00 200> this line contains start
Hello All,
I've been trying to find more resources/documentation about how to
convert python lists to C arrays (and vice versa) when writing a python
extension. Surprisingly, there's very little one can find about this
even though it must be a fairly common procedure. I looked through
official
Alan,
No use beating this dead horse...I guess that's why there are so many
languages in the first place. Different people are comfortable with
different things. (I did warn you that I like both Lisp and Prolog and
only wish I had more of a reason to use them :-)
As an aside, I did try to creat
Karen,
Put all of your code into a function, maybe called import_cobra(). The function should take the path
to the basic.out file as a parameter and return the array of data. So it will look something like this:
def import_cobra(basicPath):
cobra_xy_file = open(basicPath)
# All the same c
Actually, if I may rewrite some sections of your code -
> > example of (1):
> > -
> > #this part of the program reads the file basin.out (the data we want to
> > analyze) and changes its contents to the array arr_xy
> > #layout of basin.out:
Hi Karen,
if I have a file called foo.py =
def la()
return "la"
x = 15
I can do the following in bar.py =
import foo#Notice there's no .py extension!
j = foo.la()
print j
print foo.x
> la
> 15
Hope that helps
Liam Clarke
On Mon, 07 Feb 2005 14:40:06 +0100, Karen Leever
<[EMAIL P
Hello,
I've been writing some small python programs that basically do function
analysis on the (x,y) output of a fortran code called COBRA.
The COBRA output (basin.out) is the shape of a flexed beam, of which I
calculate the 0-crossing, x and y of max. amplitude, and cross sectional
area between
I may say this is no subject for the Python _tutor_ list ! You'll at
least want to post this message to the comp.lang.python newsgroup.
Pierre
Kent Johnson a écrit :
chandrasekhar cherukuri wrote:
http://zope.org/Documentation/Books/ZopeBook/2_6Edition/ScriptingZope.stx/Acquisition.stx
http://z
chandrasekhar cherukuri wrote:
http://zope.org/Documentation/Books/ZopeBook/2_6Edition/ScriptingZope.stx/Acquisition.stx
http://zope.org/Members/crazybrett/acquisition
Hope there is no sarcasm in this.
No, none at all. A light irony, maybe. When I first read your post, I thought, "I have no idea wh
chandrasekhar cherukuri wrote:
I completely understood what is acquisition.
I don't :-)
Can you tell us what you mean by acquisition? I see Zope has something called acquisition; I can't
think of anything by that name in standard Python...
Kent
Now can
some one explain me where it is useful and
I completely understood what is acquisition. Now can
some one explain me where it is useful and give some
contextual examples where we can see the power of
acquisition.
regards
chandu.
__
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty
Tony Cappellini wrote:
I'm trying to generate an HTML table, from multiple lists.
There are 4 lists total, each of which *may* have a different length
from the other lists.
Each list has been stored in a master dictionary.
North=[Bill, Bob, Sue, Mary]
South=['Tim', ''Tom', 'Jim', 'John', 'Carl',
On Mon, 7 Feb 2005, Tony Cappellini wrote:
> There are 4 lists total, each of which *may* have a different length
> from the other lists. Each list has been stored in a master dictionary.
>
> North=[Bill, Bob, Sue, Mary]
> South=['Tim', ''Tom', 'Jim', 'John', 'Carl', 'Evan', 'Rich']
> etc
>
> I
Hi,
My solution might raise purist's eyebrows but here it
goes...
How about using a try loop every time you read from
the list.
try:
x=list[someno]
except:
x=nothing(or whatever)
This goes on till the all lists start returning none.
for shorter lists try throws an index out of range
excepti
Hi,
I do see a problem.
The script is fine, the problem lies else where.
Your script is trying to write log.bak to log, it
should b other way round.
i.e
srcfile = open('/var/log/httpd-access.log', 'r')
dstfile = open('/var/log/httpd-access.log.bak', 'w')
hope that fixes it.
About the effici
I'm trying to generate an HTML table, from multiple lists.
There are 4 lists total, each of which *may* have a different length from
the other lists.
Each list has been stored in a master dictionary.
North=[Bill, Bob, Sue, Mary]
South=['Tim', ''Tom', 'Jim', 'John', 'Carl', 'Evan', 'Rich']
etc
d1
53 matches
Mail list logo