Hi everybody,
I used binary.py and is a bit puzzled by the results I get when comparing the binary of decimal 2 and the value I get when I convert the binary to an int.
>>> binary(2)
'0010'
>>> int(0010)
8
>>>
Isn't the int value of this
MMmmhh ... no !
The number you wrote is equivalent to '010' and any number beginning by
'0' and not followed by "x" will be considered octal. So "10" in base 8
is ... 8 :)
If you want to convert a number from base 2 to base 10 write :
>>> int("10", 2)
2
Pierre
Johan Geldenhuys a écrit :
On Tue, 8 Feb 2005, Johan Geldenhuys wrote:
> I have a data packet in Hex values and need to determine how to
> calculate the CRC-16 bit checksum for these values:
>
> 0x55,0x00,0x0A,0x01,0x01, 0x01,0xFF,0x00,0xDC,0xCC
> Sync|Lenght |source addr|dest. adr |Data| CRC check|
>
> This example sh
Subject: Re: [Tutor] Hex to Str - still an open issue
Date: Tue, 8 Feb 2005 10:29:07 -
MIME-Version: 1.0
Content-Type: text/plain;
charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produc
Alan,
That's no good. You still get something printed out. In this case:
None
Jeff
-Original Message-
From: Alan Gauld [mailto:[EMAIL PROTECTED]
Sent: Monday, February 07, 2005 6:15 PM
To: Smith, Jeff; Bob Gailer; tutor@python.org
Subject: Re: [Tutor] Are you allowed to shoot camels
Johan Kohler wrote:
> 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.
>
[successful usecase]
>
> but (2) fails with the following error:
>
> <__main__.User ins
Jeff,
It looks like that finally is the simplest expression of the original
switch statement:
import sys
def p():
pass
ftable = { 'a' : lambda: sys.stdout.write('a\n'),
'b' : lambda: sys.stdout.write('b or c\n'),
'c' : lambda: sys.stdout.write('b or c\n'),
'd'
Hello! How can I instruct Python to match on the current line and the
next line?
Assumptions;
- We are reading in one line at a time
BROKEN EXAMPLE (discussion)
##
file = open('/somefile','r').readlines()
for line in file:
match_one = re.search('^Python', line)
MMmh ... one way to do that :
Py> file_content = open('/somefile', 'r').readlines()
Py> next_file_content = iter(file_content)
Py> next_file_content.next()
Py> for (line, next_line) in izip(file_content, next_file_content):
Py> match_one = re.search('^Python', line)
Py> match_two =
Tom Tucker wrote:
Hello! How can I instruct Python to match on the current line and the
next line?
BROKEN EXAMPLE (discussion)
##
file = open('/somefile','r').readlines()
for line in file:
match_one = re.search('^Python', line)
match_two = re.search('^\tBLAH', li
Hmm, this would be a good use of itertools.tee() (Python 2.4 only):
import itertools
iter1, iter2 = itertools.tee(open('/somefile', 'r'))
iter2.next()
for line, next_line in izip(iter1, iter2):
...
Kent
Pierre Barbier de Reuille wrote:
MMmh ... one way to do that :
Py> file_content = open('/somef
Greetings,
I am
trying to use python to run a SAS program by passing the needed
parameters. I am able to start SAS, but unable to start the correct SAS
program with its parameters.
Any
assistance you could provide will be appreciated.
Tom Williams
DSHS - Research and Data Analy
> That's no good. You still get something printed out. In this case:
>
> None
Of course, silly me, p will return the default value None, you need
to replace the pass with return '' or, I guess use the lambda...
> ftable = { 'a' : lambda: 'a',...
> 'd' : lambda: ''}
Now it should wor
I have a bit of code that uses
a module and I am trying to get more info on the error.
I am using this bit of code:
try:
rhfill =
Ngl.contour(wks,rhisobar,rh_res)
except:
execType,value,tracebak
= sys.exc_info()[:3]
print execType
prin
Not to be nit-picky but it's still not the same. The switch would give
no output but yours would give a newline. I think the sys write
solution would be the closest equivalent...and took a lot longer for us
to code correctly :-)
Jeff
-Original Message-
From: Alan Gauld [mailto:[EMAIL PR
On Tue, 8 Feb 2005, Ertl, John wrote:
> I have a bit of code that uses a module and I am trying to get more info
> on the error.
>
> I am using this bit of code:
>
> try:
> rhfill= Ngl.contour(wks,rhisobar,rh_res)
> except:
> execType,value,tracebak = sys.exc_info()[:
Danny,
That is great...every time I have a problem someone has already solved
it...the other problem is finding that solution...Thanks again.
John Ertl
-Original Message-
From: Danny Yoo [mailto:[EMAIL PROTECTED]
Sent: Tuesday, February 08, 2005 10:39
To: Ertl, John
Cc: 'tutor@python.org'
Title: Printing columns of data
Hello all,
I am writing a program to take a data file, divide it up into columns and print the information back with headers. The data files looks like this
0.0 -3093.44908 -3084.59762 387.64329 26.38518 0.3902434E+00 -0.6024320E-04 0.4529416
Smith, Jeff wrote:
Jeff,
It looks like that finally is the simplest expression of the original
switch statement:
import sys
def p():
pass
ftable = { 'a' : lambda: sys.stdout.write('a\n'),
'b' : lambda: sys.stdout.write('b or c\n'),
'c' : lambda: sys.stdout.write('b or c\n'
Kooser, Ara S wrote:
Hello all,
I am writing a program to take a data file, divide it up into columns
and print the information back with headers. The data files looks like this
0.0 -3093.44908 -3084.59762 387.6432926.38518 0.3902434E+00
-0.6024320E-04 0.4529416E-05
1.0 -3
> Not to be nit-picky but it's still not the same. The switch would
give
> no output but yours would give a newline. I think the sys write
> solution would be the closest equivalent...and took a lot longer for
us
> to code correctly :-)
I can't really argue with that! :-)
Me, I'm blaming the lam
At 01:03 PM 2/8/2005, Kooser, Ara S wrote:
Content-class:
urn:content-classes:message
Content-Type: multipart/alternative;
boundary="_=_NextPart_001_01C50E19.4E45912A"
Hello all,
I am writing a program to take a data file,
divide it up into columns and print the information back w
As one last option... (And I confess I've kind of got off the
original thread here, this is just catching my interest now! :-)
try:
ftable = { 'a' : lambda: 'a',
'b' : lambda: 'b or c',
'c' : lambda: 'b or c' }
print ftable[var]
except KeyError: pass
Which is
> I am trying to use python to run a SAS program by passing the needed
> parameters. I am able to start SAS, but unable to start the correct
SAS
> program with its parameters.
Not being familiar with SAS or its parameters we'll need more clues...
> Any assistance you could provide will be apprec
> So I wrote the program included below and it only prints the last
line
> of the file.
> I have one question. Do I need to put ts and pe into a list before I
> print then to screen or I am just missing something. Thanks.
You just need to indent your last print statement so it is inside
the loop
> table = { 'a': 'a', 'b': 'b or c', 'c': 'b or c', 'd': None }
> result = table.get(var, 'default case')
> if result:
> print result
>
> This, to my mind, is much cleaner -- you're factoring out the
repeated
> code, whether print statement or call to sys.stdout.write(),
reducing
> the complex
I'll do my best to answer these questions for you.
I am able to start the SAS executable from python, but not the specific SAS
program in question. When this executable is executed, the typical SAS
environment is displayed (SAS editor Window, SAS libraries, and the output
and log windows). I wan
Ah, SAS. I used that a lot in the early '80s for general programming. I
felt a lot about SAS then as I do about Python now.
Enough of that. Can you show your python code that invokes SAS; and can
you also show what you type at a command line that makes SAS run the
way you want?
Given the c
Liam Clarke wrote:
oh? Is is the negative?
No, the decimal fraction. It's easy enough to try it:
Not exactly, it's a combination of string *and* decimal fraction.
int('-945')
-945
int('-945.0')
Traceback (most recent call last):
File "", line 1, in ?
ValueError: invalid literal for int(): -945.0
i
import os
srcfile = open('/var/log/httpd-access.log.bak', 'r')
dstfile = open('/var/log/httpd-access.log', 'w')
while 1:
lines = srcfile.readlines()
if not lines: break
#print lines
for i in lines:
if len(i) < 2086:
#print i
dstfile.write(i)
srcfile.c
It's getting late, so if someone already suggested something like this, just
pretend to smack me across the face, and I'll flinch later...
import re
fi = open('/somefile','r') ## Don't do readlines and bring the whole file
in memory...
match1 = re.compile('^Python')
match2 = re.compile('^/tBLA
I want to use mysqldb to add people into a database,
but when I ask for the certain fields like Name,
PhoneNumber and such, I cannot get it to put them in
as a string? I am not sure what I am doing wrong but
here is my code thanks to anyone who helps:
import MySQLdb
username = raw_input("what is y
Shitiz Bansal wrote:
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.
Can anyone tell me what I've done wrong in this
script.
I'm trying to get only the lines that start with
"This" for a text file.
Here's what I wrote:
>>> import re
>>> f = open('c:/lines.txt').readlines()
>>> for line in f:
match = re.search('^This',f)
if line == match:
> >>This simplifies the code down to:
> >>
> >>###
> >>srcfile = open('/var/log/httpd-access.log.bak', 'r')
> >>dstfile = open('/var/log/httpd-access.log', 'w')
> >>for line in srcfile:
> >>if len(line) < 2086:
> >>dstfile.write(line)
> >>srcfile.close()
> >>dstfile.close()
> >>###
>
H Ron,
>>> import re
>>> f = open('c:/lines.txt').readlines()
>>> for line in f:
match = re.search('^This',f)
if line == match:
print match
Hi Ron,
Welcome to the wonderful world of Python.
from re.search.__doc__ ;
"Scan through string looking for a match to the
On Tue, 8 Feb 2005, james middendorff wrote:
> I want to use mysqldb to add people into a database, but when I ask for
> the certain fields like Name, PhoneNumber and such, I cannot get it to
> put them in as a string? I am not sure what I am doing wrong but here is
> my code thanks to anyone wh
37 matches
Mail list logo