problem with bcd and a number

2011-08-04 Thread nephish
Hey all,

I have been trying to get my head around how to do something, but i am
missing how to pull it off.
I am reading a packet from a radio over a serial port.

i have " two bytes containing the value i need.  The first byte is the
LSB, second is MSB.  Both bytes are BCD-encoded, with the LSB
containing digits zX and MSB containing digits xy.  The system speed
is then xyz%, where 100% means maximum speed and would be given by
bytes 00(LSB) 10(MSB)."

that is a quote from the documentation.
Anyway, i am able to parse out the two bytes i need, but don't know
where to go from there.

thanks for any tips on this.
-- 
http://mail.python.org/mailman/listinfo/python-list


problem with bcd and a number

2011-08-04 Thread nephish
Hey all,

I have been trying to get my head around how to do something, but i am
missing how to pull it off.
I am reading a packet from a radio over a serial port.

i have " two bytes containing the value i need.  The first byte is the
LSB, second is MSB.  Both bytes are BCD-encoded, with the LSB
containing digits zX and MSB containing digits xy.  The system speed
is then xyz%, where 100% means maximum speed and would be given by
bytes 00(LSB) 10(MSB)."

that is a quote from the documentation.
Anyway, i am able to parse out the two bytes i need, but don't know
where to go from there.

thanks for any tips on this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: time challenge

2005-09-23 Thread nephish
sorry about that, i got a message in my inbox that said that the post
was rejected
so i tried it from my email client.

wont happen again.
shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


never mind about the plot stuff, my mistake

2005-09-26 Thread nephish
hey,
a little update.
i got the pychart working
the examples did not include the necessary #!/usr/bin/python

its like being a literary critic forgetting how to spell his name.

thanks for your help getting the deb package going.
i should be all good now.
sk

-- 
http://mail.python.org/mailman/listinfo/python-list


another time challenge

2005-09-28 Thread nephish
Hey there pythoneers

i have another question about time, specifically, the mxDateTime
module.
i have been able to get a RelativeDateTimeDiff between two times,
it gives me a difference between two DateTimes in the form of +3days
+2hours etc...

so, if i have a date that is 6 days and 6 hours from another day,
it will give me Days+6, hours+5.

what i need is something like 6.4 days or close to it.
is there an easy way to convert this ?

if not i can write up something to do the math.

i guess i am just looking for a cleaner shortcut.

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: another time challenge

2005-09-29 Thread nephish
cool, thanks
-shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


question about smtplib

2005-10-03 Thread nephish
Hey there,

i am using the smtplib module in python 2.3

my question is, this works:

server = smtplib.SMTP(localhost)

then server.sendmail(to address, from address, message)


what i want to know is, how does the connection work?

when i do server.sendmail, does it connect then ? or did it connect
when
i made the object ?

the reason i need to know is i need to send several emails out at once
and would be best to only connect once, i think.

i know that i can call server.close(), i just dont know when it was
opened.
thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about smtplib

2005-10-03 Thread nephish
cool. so this line
server = smtplib.SMTP(localhost)
is when i connect ?

i had my syntax wrong anyway, i was using server.close()
instead of server.quit()

thanks much

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about smtplib

2005-10-04 Thread nephish
thanks for all the help,
got it working ok now, connecting once, sending many.

thanks for the link too. 

cheers,
sk

-- 
http://mail.python.org/mailman/listinfo/python-list


need some advice on x y plot

2005-10-20 Thread nephish
Hey there,
i have tried about every graphing package for python i can get to work
on my system. gnuplot, pychart, biggles, gdchart, etc.. (cant get
matplot to work)
so far, they all are working ok. I need to make an x y chart for some
data that comes in from sensors at different times durring the day. i
need it to show the value in the y and the time in the x .  no problem
so far. But what i cannot get to happen is to scale x (time of the
plot) with respect to time. in other words, i get a chart with the
times evenly spaced out along the x axis, with their respective values.
i need the chart to show gaps when there are gaps in the data. i need
it to be able to scale by time. if i have 3 values that come in within
a few minutes, i need them to be displayed close together, as compared
to another value that may come in, say, an hour later. Does this make
sence ?
one of you guys know a charting app that will do this ? or is there
some other way i could do it?

looking for suggestions,
sk

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some advice on x y plot

2005-10-20 Thread nephish
how ?
i have tried to use unix timestamps, and i have also tried with
DateTime objects
do i need to use a scale that isn't linear (default in most) ?
how do i putt this off ?

thanks btw.
sk

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some advice on x y plot

2005-10-20 Thread nephish
i have thought about doing this, just a little different. i was going
to list the value pairs.
take the start time and end time and plot 100 empty plots between them.
add the value pairs, sort by time, and then draw it. The only thing is
it get kinda complicated when the times change a lot. they could span
an hour, a month, anything in between.

i like your idea, i will check various packages for how to plot 'none'

thanks
sk.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some advice on x y plot

2005-10-20 Thread nephish
ok, yeah, thats exactly what i am looking for. i will give it a go.
thanks a whole lot.

putt this off is a typo, pull this off is what i was meaning to type.

this is cool.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some advice on x y plot

2005-10-21 Thread nephish
ok, i tried something similar to what you posted.
a little simpler though.
i am running a query on a database and making a list of time, value
pairs
kinda like this
plot_points = ([time, value], [time, value], [time, value])
gnuplot complains that it needs a float for one of the values.
i can plot just the value, and it shows up ( no x value found)

how should i proceed?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some advice on x y plot

2005-10-21 Thread nephish
the time is DateTime.DateTime object from a mySQLdb query.
the value is a number anywhere between 0 and 15.
the datetime is formatted like 2005-10-20 08:40:34

i could strip it and make a timestamp out of it. but reading the
number of seconds since january of 1970 doesn't make a neat chart.

any suggestions?

oh, and can you output from Gnuplot to a png or jpeg or something like
that.
the Gnuplot documentation says that it can make a bitmap png but i dont
know how to do that with the python wrapper. the docs for this are a
little cryptic.
still a newbie here. if you know a good tutorial on this, i would
really appreciate the link.

thanks for your time, and brain

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some advice on x y plot

2005-10-21 Thread nephish
ok, i have a display, and its a work in progress.

lemme get this straight. you used

gp('set term png')

is this an example of sending normal gnuplot commands?
if so, are all of the gnuplot commands available ?
thanks so much this is helping me out a lot here

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some advice on x y plot

2005-10-21 Thread nephish
this is great, because the docs on gnuplots website are a bit easier
for me to grasp.
thanks so much for your time on this one. you really have helped me a
lot.
i will not get a change to work on this till monday. so i may have more
questions then. This is sure a point in the right direction.

thanks much.
shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some advice on x y plot

2005-10-24 Thread nephish
ok, i am stuck a bit here with this line

gp('set xtics (%s)' % ','.join(ticstrings))

the error code says that it is looking for a closing parenthesis.
that and i am kinda new enough not to really get what %s is all about.
i know it formats a string.

can you simply pass a list to 'set xtics' ?

i mean, i got this from the gnuplot site

Syntax:

 set xtics {axis | border} {{no}mirror} {{no}rotate {by }}
   {offset  | nooffset}
   {  autofreq
| 
| ,  {,}
| ({""}  {} {,{""}...) }
   { font "name{,}" }
   { textcolor  }
 unset xtics
 show xtics

but it does not look like all the options are necessary from the docs,
i guess i am asking, if i just wanted to pass a list of say, 14 tics to
the x axis as a list, what of the above is necessary ?

i built the list by taking time stamps in seconds (the same as being
plotted for x) took the end time minus the start time and divided by
12, incremented each by this amount until i had 12 plots (plus of
course the first and last).
these are all stored in plot_times[]..

any tips ?

sorry if this all sounds a bit scrambled. i just got the hang of
changing from a datetime.datetime to time in epoch seconds. ( these
little triumphs keep me going )

thanks for your help. the graph i built looks great, and looks right
referenced with time. just neeed to print the x a little easier to
read.

thanks again,

shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some advice on x y plot

2005-10-25 Thread nephish
well, for what i tried, ticstrings just contained a list of times
formatted like
[10-21 09:15, 10-21 09:44, 10-21 09:59, and so on.]
i did write mine a little different than the example that Grant gave me
because its a little
different application of time.

i think i am having trouble knowing exactly what the set xtics line is
looking for.
thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some advice on x y plot

2005-10-25 Thread nephish
Ok, first off, thanks for all the help guys,

this part " set xtics  ("label" pos, "label" pos, "label" pos) "
is mainly what i was confused about. the 'pos' part. i think that the
way i am writing
this leaves this out. in fact, i am pretty sure.

here is the code i am trying out.

def draw_chart(self, StartTime, EndTime):
# make start time and end time markers in  seconds
start_tic = time.mktime(time.strptime(StartTime, '%Y-%m-%d
%H:%M:%S'))
end_tic = time.mktime(time.strptime(EndTime, '%Y-%m-%d %H:%M:%S'))
# get the difference in seconds between start and end times
diff_time = start_tic - end_tic
# get tick marks with respect to time
tic_increment = diff_time / 15
#build an array of ticmarks
tics_raw = []
tics_raw.append(start_tic)
tic_adder = start_tic
for x in range(13):
tic_adder = tic_adder + tic_increment
tics_raw.append(tic_adder)

#add the last time to the tics array
tics_raw.append(end_tic)

# change all the tic increments to reader understandable values
tics = []
for x in tics_raw:
tics.append(time.strftime('%m/%d %H:%M', time.localtime(x)))
print 'tic '+(time.strftime('%m/%d %H:%M', time.localtime(x)))

# get the plot points date / value
Sensor =  self.GraphSensorEntry.get_text()
db = MySQLdb.connect(host="localhost", user="piv",
passwd="crayon99", db="DDS")
cursor=db.cursor()
cursor.execute("SELECT `Raw`, `DateTime` FROM `Process` WHERE
`Sensor_ID` = '"+Sensor+"' \
AND `DateTime` > '"+StartTime+"' AND `DateTime` < '"+EndTime+"'
ORDER BY `DateTime` ")
results = cursor.fetchall()
plot_x = []
plot_y = []
for row in results:
Value = row[0]
#convert datetime.datetime object to epoch (seconds) object
Time = time.mktime(row[1].timetuple())
print time.strftime('%m/%d %H:%M:%S', time.localtime(Time))

plot_x.append(float(Time))
plot_y.append(float(Value))
g = Gnuplot.Gnuplot(debug=1)
g.title('testing')
data = Gnuplot.Data(plot_x,plot_y)
outfile = '/home/piv/PivData/tmp/images/graph.png'
g('set term png')
g('set out "%s"' % outfile)
g('set xtics (%s)' % (tics))
g.plot(data)

self.GraphImage.set_from_file('/home/piv/PivData/tmp/images/graph.png')



and this is the terminal output i get

gnuplot> set title "testing"
gnuplot> set term png
gnuplot> set out "/home/piv/PivData/tmp/images/graph.png"
gnuplot> set xtics (['10/18 09:54', '10/17 22:42', '10/17 11:30',
'10/17 00:18', '10/16 13:06', '10/16 01:54', '10/15 14:42', '10/15
03:30', '10/14 16:18', '10/14 05:06', '10/13 17:54', '10/13 06:42',
'10/12 19:30', '10/12 08:18', '10/25 09:54'])
gnuplot> plot '/tmp/tmpn2URt2' notitle

gnuplot> set xtics (['10/18 09:54', '10/17 22:42', '10/17 11:30',
'10/17 00:18', '10/16 13:06', '10/16 01:54', '10/15 14:42', '10/15
03:30', '10/14 16:18', '10/14 05:06', '10/13 17:54', '10/13 06:42',
'10/12 19:30', '10/12 08:18', '10/25 09:54'])
^
 line 0: invalid expression


it is drawing the graph though, and it looks right compared with the
data

i noticed in the docs for gnuplot, that it can do date/time and by
default uses seconds since 2000. and then you can pass the format that
you want to show it in.
would this give the same kind of result that i am looking for ?


my math in how i am doing this is kinda off too, i think.
for the stuff i am doing on our website, i use php with jpgraph, it
does things a little
different. 

thanks for everything
shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some advice on x y plot

2005-10-25 Thread nephish
 tics.append('"%s" %s' % (time.strftime(...), x))
# might need time.localtime(x) for that last term.

ok, tried this and it worked.
but the first plot is at the last plot of data
back to that math mistake i mentioned earlier.
so, thanks much, i will be back when i mess around with it some more
and
see if i can get it right.
thanks very very much guys,

i know i sound frustrated and ignorant, but i am having a lot of fun
with this

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some advice on x y plot

2005-10-25 Thread nephish
WE DID IT !
little more tinkering and correcting this
diff = start_time - end_time (vrs the other way around)

and its working.

so many thanks gents, a lot !

-- 
http://mail.python.org/mailman/listinfo/python-list


how do i run another script from my python script

2005-10-27 Thread nephish
hey there all,
i have been looking for a way to run a php command line script from my
python script.

here is what i want to do:

if x = 4:
execute php4 testin.php
else:
execute php4 testout.php

and i also need the script to wait untill the php4 script is done
(which i think is the default ) before continuing to run.

i know this is possible, but how?
thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do i run another script from my python script

2005-10-27 Thread nephish
man, thats just too easy.
thanks much !

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do i run another script from my python script

2005-10-27 Thread nephish
well i know i dont want to do another thread, my program has six
running all the time.
whew. that can get nuts.
i mean, this will come to me easier later i am sure. But right now.
simple is best.
thanks for all the suggestions, gents.
right now i am just doing a varient of Steves suggestion, and so far,
its working.

thanks again,
sk

-- 
http://mail.python.org/mailman/listinfo/python-list


need start point for getting html info from web

2005-10-30 Thread nephish
hey there,

i have a small app that i am going to need to get information from a
few tables on different websites. i have looked at urllib and httplib.
the sites i need to get data from mostly have this data in tables. So
that, i think would make it easier. Anyone suggest a good starting
point for me to find out how to do this, or know of a link to a good
how-to?
thanks,
sk

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need start point for getting html info from web

2005-10-30 Thread nephish
yeah, i know i am going to have to write a bunch of stuff because the
values i want to get come from several different sites. ah-well, just
wanting to know the easiest way to learn how to get started. i will
check into beautiful soup, i think i have heard it referred to before.
thanks
shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


question about urllib and parsing a page

2005-11-02 Thread nephish
hey there,
i am using beautiful soup to parse a few pages (screen scraping)
easy stuff.
the issue i am having is with one particular web page that uses a
javascript to display some numbers in tables.

now if i open the file in mozilla and "save as" i get the numbers in
the source. cool. but i click on the "view source" or download the url
with urlretrieve, i get the source, but not the numbers.

is there a way around this ?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about urllib and parsing a page

2005-11-02 Thread nephish
thats cool, but i want to do this automatically with python.
what can i do to have urllib download the source with the numbers in
it?

ok, not necessarily urllib, whatever one is best for the occation
thanks 
shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about urllib and parsing a page

2005-11-02 Thread nephish
well, i think thats the case, looking at the code, there is a long
string of math functions in page, java math functions. h. i guess
i'm up that famous creek.
thanks for the info, though
shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


need help extracting data from a text file

2005-11-07 Thread nephish
Hey there,
i have a text file with a bunch of values scattered throughout it.
i am needing to pull out a value that is in parenthesis right after a
certain word,
like the first time the word 'foo' is found, retrieve the values in the
next set of parenthesis (bar) and it would return 'bar'

i think i can use re to do this, but is there some easier way?
thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need help extracting data from a text file

2005-11-07 Thread nephish
this is cool, it is only going to run about 10 times a day,

the text is not written out like foo(bar) its more like
foo blah blah blah (bar)

the thing is , every few days the structure of the textfile may change,
one of the reasons i wanted to avoid the re.

thanks for the tip,

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need help extracting data from a text file

2005-11-07 Thread nephish
um, wait. what you are doing here is easier than what i was doing after
your first post.
thanks a lot. this is going to work out ok.

thanks again.
sk

-- 
http://mail.python.org/mailman/listinfo/python-list


question about extracting value from a string

2005-12-07 Thread nephish
hey there,

i have looked at the string module and re.
i was looking for advice on what would be the best way to pull a value
out of a small string.

for example, i have a string
$.+.09 JAR
   and all i want out of it is the +.09

likewise, i have
$-.04 TIN kt
  and all i want is the -.04

what would be my best bet here ?
do i need a full blown re comparison? 

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about extracting value from a string

2005-12-07 Thread nephish
the second line was not a typo , and thanks for that.
these values may vary somewhat over time. So i may have to rewrite this
part of the script.

a string is fine for right now, because it is just going to be pumped
into a database. i can change it later if necessary.

thanks for the help gents, i am going to just go with string functions,
seems like it will be easier both to code now. and later if and when
the format of this stuff may change.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about extracting value from a string

2005-12-07 Thread nephish
>I agree -- "to each day are sufficient the evils thereof".  Many
>programmers fall into the temptation to overgeneralize and fail to
>follow the AGNI principle ("Ain't Gonna Need It"...;-).

thats funny :)

-- 
http://mail.python.org/mailman/listinfo/python-list


need to strip stuff off email

2005-06-21 Thread nephish
hey there,
i have a script that retrieves my email, but i need it to
be able to strip all the stuff off except the body (the message itself)
so i can later write it to a text file.

anyone know how to accomplish this?
thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


some trouble with MySQLdb

2005-06-29 Thread nephish
Hey there all,
i have a question about how to point my python install to my sql database.

when i enter this: db = MySQLdb.connect(user="user", passwd="pass", 
db="myDB")

i get this:
Traceback (most recent call last):
  File "", line 1, in -toplevel-
db = MySQLdb.connect(user="user", passwd="pass", db="MyDB")
  File "/usr/lib/python2.4/site-packages/MySQLdb/__init__.py", line 66, 
in Connect
return Connection(*args, **kwargs)
  File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line 
134, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1049, "Unknown database 'MyDB'")

i am using the all in one package from lampp (now xampp) and i have 
tested a couple of python scripts from the cgi, but nothing that 
connects to the database.

any ideas?

thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


need help with MySQLdb

2005-06-29 Thread nephish
Hey there all,
i have a question about how to point my python install to my sql
database.

when i enter this: db = MySQLdb.connect(user="user", passwd="pass",
db="myDB")

i get this:
Traceback (most recent call last):
  File "", line 1, in -toplevel-
db = MySQLdb.connect(user="user", passwd="pass", db="MyDB")
  File "/usr/lib/python2.4/site-packages/MySQLdb/__init__.py", line 66,
in Connect
return Connection(*args, **kwargs)
  File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line
134, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1049, "Unknown database 'MyDB'")

i am using the all in one package from lampp (now xampp) and i have
tested a couple of python scripts from the cgi, but nothing that
connects to the database.

any ideas?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


need to get an index for an item in a list

2005-07-03 Thread nephish
hey there,
i need to be able to get the index for an item in a list.
the list is a list of lines read from a text file.

like this:

file = open("/home/somefile.text", "r")
lines = file.readlines()
file.close()

now, i want to see if a certain string is == to one of the lines
and if so, i need to know the index of that line.

any ideas?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need to get an index for an item in a list

2005-07-03 Thread nephish
Hey, thanks, this has worked out for me.
i am trying to do as much of this as possible in IDLE because
it lets me know on the fly what is messed up.
thanks for your help
shawn <><

-- 
http://mail.python.org/mailman/listinfo/python-list


how to write a line in a text file

2005-07-25 Thread nephish
Hey there,
kinda newbie question here.
i know how to read the lines of a txt file.
i know how to write a txt file.

but how do i overwrite a line value with another value ?

i mean, how do go to, say, line 3 of a text file and replace
what is written on line 3 with something else?

thanks
<><

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to write a line in a text file

2005-07-25 Thread nephish
Gee whiz, so easy.
thanks. Never thought about just changing it while it was read then
re-writing it. that will be just fine. these files are only 9 lines
long.
thanks again !

-- 
http://mail.python.org/mailman/listinfo/python-list


need some info on MySQL module.

2005-07-26 Thread nephish
Hey there, does anyone know where i can find some real documentation on
the MySQLdb module? This thing is driving me nuts. all i can find on
the internet is some brief tutorials. I need to know whats up with some
of my stuff i even bought Programming Python by O'Reilly, out of over
1200 pages, and it only has a page or two dedicated to it.

eeek. Thanks.
<><

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some info on MySQL module.

2005-07-26 Thread nephish
Wow, thanks so much. I promise, i didn't know that was out there.
should help me out a lot.
still a newbie here, somewhat.
thanks again
<><

-- 
http://mail.python.org/mailman/listinfo/python-list


question about deleting records from mysql

2005-07-27 Thread nephish
Hey there,
sorry , second question in as many days.
i am trying to do some stuff with MySQLdb and the thing is, i can
select records and such, but when i try to delete them, they dont
really go away.

like this

>>> cursor.execute("DELETE FROM table WHERE autoinc > 1000")
240L
>>> cursor.execute("SELECT * FROM table WHERE autoinc > 1000")
0L

so it looks like it worked, but when i use something else to look at
the
table (phpmyadmin, mysql-query-browser, knoda) the records are still
there!

what do i do?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about deleting records from mysql

2005-07-27 Thread nephish
Simon Brunning wrote:

>On 27 Jul 2005 04:29:33 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>  
>
>>Hey there,
>>sorry , second question in as many days.
>>i am trying to do some stuff with MySQLdb and the thing is, i can
>>select records and such, but when i try to delete them, they dont
>>really go away.
>>
>>
>
>A fiver says you need to commit your changes.
>
>  
>
ok, do i do that with cursor.commit() ?
thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about deleting records from mysql

2005-07-27 Thread nephish
ok. did this

>>> cursor.execute("DELETE FROM table WHERE autoinc > 1000")
245L
>>> cursor.commit()

i got an AttributeError 'Cursor' object has no attribute 'commit'

hmm. what should i do now?
the stuff about writing a lightweight layer between the dbapi and the
program shot right over my head. sorry, but thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about deleting records from mysql

2005-07-27 Thread nephish
Man, thanks for the link. and the tip. i am testing
the db.commit() and printing the doc right now.
thanks again.


On 07/27/2005 07:43:24 AM, Rowdy wrote:
> [EMAIL PROTECTED] wrote:
>> ok. did this
>> 
>> 
> cursor.execute("DELETE FROM table WHERE autoinc > 1000")
>> 
>> 245L
>> 
> cursor.commit()
>> 
>> 
>> i got an AttributeError 'Cursor' object has no attribute 'commit'
>> 
>> hmm. what should i do now?
>> the stuff about writing a lightweight layer between the dbapi and the
>> program shot right over my head. sorry, but thanks
>> 
> 
> IIRC it is the connection that can commit(), not the cursor.
> 
> Rowdy
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


easy float question just eludes me

2005-07-28 Thread nephish
Hullo all !

i have a real easy one here that isn't in my book.
i have a int number that i want to divide by 100 and display to two
decimal places.

like this float(int(Var)/100)
but i need it to display the .00 even if it does not have a .00 value
like this
if Var is 50, i need to display .50 instead of just .5

i know there is an easy way to do this.
thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy float question just eludes me

2005-07-28 Thread nephish
way cool, outta work out just fine

On 07/28/2005 08:48:27 AM, Simon Brunning wrote:
> On 28 Jul 2005 06:39:32 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
> wrote:
> > i have a real easy one here that isn't in my book.
> > i have a int number that i want to divide by 100 and display to two
> > decimal places.
> >
> > like this float(int(Var)/100)
> > but i need it to display the .00 even if it does not have a .00
> value
> > like this
> > if Var is 50, i need to display .50 instead of just .5
> 
> >>> import decimal as dec
> >>> dec.Decimal('250.00')/100
> Decimal("2.50")
> 
> --
> Cheers,
> Simon B,
> [EMAIL PROTECTED],
> http://www.brunningonline.net/simon/blog/
> 
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy float question just eludes me

2005-07-28 Thread nephish
oops, i dont seem to have a module decimal
-shawn

On 07/28/2005 08:48:27 AM, Simon Brunning wrote:
> On 28 Jul 2005 06:39:32 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
> wrote:
> > i have a real easy one here that isn't in my book.
> > i have a int number that i want to divide by 100 and display to two
> > decimal places.
> >
> > like this float(int(Var)/100)
> > but i need it to display the .00 even if it does not have a .00
> value
> > like this
> > if Var is 50, i need to display .50 instead of just .5
> 
> >>> import decimal as dec
> >>> dec.Decimal('250.00')/100
> Decimal("2.50")
> 
> --
> Cheers,
> Simon B,
> [EMAIL PROTECTED],
> http://www.brunningonline.net/simon/blog/
> 
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


getting an empty tuple

2005-07-31 Thread nephish
Hey there,
i have a simple database query that returns as a tuple the number of
rows that the query selected.
kinda like this

>>> cursor.execute('select value from table where autoinc > 234')
>>> x = cursor.fetchall()
>>> print x

>>> 21L

ok, means 21 rows met the criteria of the query. but if there are none
that match,
like i do a

>>> print x
>>> 0L

how do i encorporate that into an equation ?
i have tried all kinds of stuff

if x == 0L
if x(0) == None
if x == None

anyway, what shoud i do to test if the result is empty?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting an empty tuple

2005-07-31 Thread nephish
ok, this is what works:
 if x == ():

sorry about the bad info. and what i ment to put was
x[0] not x(0)

thanks for the tips
its all good now

shawn


Steven D'Aprano wrote:
> On Sun, 31 Jul 2005 08:40:26 -0700, nephish wrote:
>
> > Hey there,
> > i have a simple database query that returns as a tuple the number of
> > rows that the query selected.
> > kinda like this
> >
> >>>> cursor.execute('select value from table where autoinc > 234')
> >>>> x = cursor.fetchall()
> >>>> print x
> >
> >>>> 21L
>
> 21L is not a tuple, it is a long integer.
>
> > ok, means 21 rows met the criteria of the query. but if there are none
> > that match,
> > like i do a
> >
> >>>> print x
> >>>> 0L
> >
> > how do i encorporate that into an equation ?
> > i have tried all kinds of stuff
>
> And did they work? If they didn't work, tell us the exact error message
> you got.
>
>
> > if x == 0L
>
> If x is a long integer, then that will work. Of just "if x == 0:" will
> work too.
>
>
> > if x(0) == None
>
> No. That means x is a function, and you are giving it an argument of 0,
> and it returns None.
>
> > if x == None
>
> You said that your query returns a tuple, but then gave an example where
> it returns a long int. None is not a tuple, nor a long int, so testing
> either of those things against None will never be true.
>
> Did you try any of these things in the interactive interpreter? Python is
> a great language for experimenting, because you can try this yourself:
>
> # run your setup code ...
> # and then do some experimenting
> cursor.execute('select value from table where autoinc > ')
> # or some value that will never happen
> x = cursor.fetchall()
> print x
>
> What do you get?
>
>
> > anyway, what shoud i do to test if the result is empty?
>
> Long ints are never empty, but they can be zero:
>
> if x == 0:
> print "no rows were found"
> elif x == 1:
> print "1 row was found"
> else:
> print "%d rows were found" % x
>
> Tuples can be empty:
>
> if len(x) == 0:
> print "no rows were found"
>
> or if you prefer:
>
> if x == ():
> print "no rows were found"
>
>
> But the cleanest, most Pythonic way is just to do a truth-test:
>
> if x:
> print "something was found"
> else:
> print "x is empty, false, blank, nothing..."
> 
> 
> -- 
> Steven.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUI programming, embedding, real time plots, etc.

2005-08-05 Thread nephish
apt-get install python-pwm
this will get you python mega widgets
one of the dependencies that apt will take care of for you is the
python2.whatever-tk.
depending on which version of debian you are using.
i run sarge with python 2.3

-- 
http://mail.python.org/mailman/listinfo/python-list


question about binary and serial info

2005-08-17 Thread nephish
i have an interesting project at work going on. here is the challenge.
i am using the serial module to read data from a serial input.
it comes in as a hex. i need to make it a binary and compare it bit by
bit to another byte. They have some weird way they set this up that i
have to compare these things with AND. in other words, if bit 1 is 1
AND bit 1 is 1 then the real value is 1...

long story short. is there a good way to compare bytes, bit by bit with
one of the modules of python. i want to know so i dont get halfway into
developing this and find that there is a much better way to do this
than by hand.

thanks for any suggestions.
sk <><

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about binary and serial info

2005-08-17 Thread nephish
yeah, i think i got that down, i need help with getting the hex to
binary, then splitting the byte up to compare each bit against the bit
in another byte.
unless i am not understanding this stuff with the bitwise right. there
wasn't a lot in the python library reference about it.
thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about binary and serial info

2005-08-18 Thread nephish
this is exactly what i need.
i have not previously had a need for this kind of thing, but i sure
need some
documentation for it now. is there a resource out there to find out how
to convert decimal number to a byte, a byte to a decimal and more about
the & operator?
i really appreciate this info. this is exactly what i was looking for.
shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about binary and serial info

2005-08-18 Thread nephish
oh wait, i found it. i found how to do the conversions and thanks to
you the operators.
appreciate everything,
shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about binary and serial info

2005-08-18 Thread nephish
i got the bitwise part, i just cant seem to convert the incomming ascii
into hex, binary, integer, or decimal.
how do i do this, my serial port bytes just come in all weird looking
ascii characters
thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about binary and serial info

2005-08-18 Thread nephish
i have an ascii string comming in the serial port and i need to convert
it to something else, like an integer, or binary, or even a hex so i
can use the bitwise comparison on it.
thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about binary and serial info

2005-08-18 Thread nephish
>>> import serial
>>> ser = serial.Serial('/dev/ttyS0', 2400, timeout= 10, bytesize=8, stopbits=1)
>>> a = ser.read(1)
>>> print a
^
>>> ser.close()

>>> type(a)


>>> int(a, 16)
Traceback (innermost last):
  File "", line 1, in ?
ValueError: invalid literal for int(): ^

so i run it again the same way, only reading 4 bytes this time.

>>> ser = serial.Serial('/dev/ttyS0', 2400, timeout= 10, bytesize=8, stopbits=1)
>>> a = ser.read(1)
>>> print a
^Aรœร€
>>> ser.close()

>>> type(a)



int(a, 16)
Traceback (innermost last):
  File "", line 1, in ?
ValueError: invalid literal for int(): ^Aรœร€

i dont understand what i am missing here.
the string character represents a hex character.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about binary and serial info

2005-08-18 Thread nephish
all apologies, gentlemen, i feel like an idiot.
the ord() is what is returning what i need.
the manufacturer of the unit i am reading from
told me that it puts out a "string that represents a hex"
been thumping my head.
sorry for the confusion, 
and thanks for your help
shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about binary and serial info

2005-08-18 Thread nephish
thanks for your time.
i have started just doing a type(a) from idle a lot just so i can make
sure of what i am dealing with ( i do this a lot) before i build the
.py file. got tired of 'cannot concatonate str and init' stuff all the
time.
this has been a wild project. nothing like getting in way over your
head to crash learn something. i really dig python. just was going
outta my onion over this one.

thanks again
shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about binary and serial info

2005-08-21 Thread nephish
Sorry i am late getting back on this.
ord() is finally what is giving me what i wanted.
the vendor told me that what was comming in was an ascii string
representing hex characters. So i expected when i used the serial
module
that what i would be getting was something along the lines of 4A, 3D,
etc..
but i got weird characters. So then (with the help of this very thread)
discovered that i am reading raw bytes. i am supposed to validate the
bytes as they come in because the message comes in four at a time. and
i validate each byte
like this
var = (validation number)
a = ser.read(1)
x = ord(a)
then to validate : x = (x & var)

I am really sorry about the confusion. i am really new at this.
but i am getting what i am supposed to now.

i dont have the details on the script, because it is at work.
but i will post it monday.
thanks for everything.
i would still be banging my head if not for this thread

-- 
http://mail.python.org/mailman/listinfo/python-list


need a little help with time

2005-08-26 Thread nephish
Hey there.
i have a time string (created with strftime) then read from a file,
i am having some trouble understanding how to get the difference
between times.
i know i can structime(timestring) and get a time value, but i dont
know how to manipulate it.

basically, if i have string 2005-08-24 09:25:58
and another string 2005-08-24 09:28:58

how can i tell how many minutes, hours, seconds, days, months etc..
have passed between the first string and the second ?

or, if there is a good tutorial on this kind of thing, please post a
url.

thanks

shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need a little help with time

2005-08-26 Thread nephish
the mxDateTime thing should be great, i have to pass this stuff back
and forth with MySQL DateTime fields,
thanks a lot !

-- 
http://mail.python.org/mailman/listinfo/python-list


trouble with time --again

2005-08-30 Thread nephish
Hey there,
could someone show me where i am going wrong here?

>>> date1 = '2005-01-01 8:20:00'
>>> date1 = strptime('%Y-%m-%d %H:%M:%S',date1)

raise ValueError("time data did not match format:  data=%s  fmt=%s" %
ValueError: time data did not match format:  data=%Y-%m-%d%H:%M:%S
fmt=2005-01-01 8:20:00

i have looked over the strptime and strftime over and over, dont get
where i am missing it here.

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trouble with time --again

2005-08-30 Thread nephish
OH my god.
youre right.
i feel like a complete idiot.
thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trouble with time --again

2005-08-30 Thread nephish
he he. yep, just spent a lot of time on this one.
life moves on.
cheers!
sk

-- 
http://mail.python.org/mailman/listinfo/python-list


can i move attribute values from one class to another?

2005-09-07 Thread nephish
heres the deal.
i am working on a threading gui. pygtk
in one class (main) is all the gui stuff,
but in another class that is a thread, i am reading serial input.
what i want to be able to do is take what read in the thread and
print it in a textview in the gui class.

here is what i have:


class Serial1(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)


def run(self):
ser = serial.Serial('/dev/ttyS15', 2400, timeout=None)
loopy = 1
while loopy < 5:
for x in range(5):
Input1Data = 'buncha data and timestamp\n'
gobject.idle_add(self.buffer_add,  Input1Data)

def buffer_add(self,  Input1Data):
Input1Iter = self.Input1Buffer.get_end_iter()
self.Input1Buffer.insert(Input1Iter, Input1Data)


class Main(SimpleGladeApp):
def __init__(self, path="pivcontrolcenter.glade",
 root="Main",
 domain=app_name, **kwargs):
path = os.path.join(glade_dir, path)
SimpleGladeApp.__init__(self, path, root, domain, **kwargs)
self.MessageBuffer = self.MessageView.get_buffer()

def on_StartEnginesButton_clicked(self, widget, *args):
Input1Iter = self.MessageBuffer.get_end_iter()
Input1Data = 'Reading Serial device ttyS14 \n'
self.Input1Buffer.insert(Input1Iter, Input1Data)
time.sleep(1)
S1 = Serial1()
S1.start()

basically, i need a way to pass data, actually the control of the
textview wiget 
in and out of a class.
is this possible?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can i move attribute values from one class to another?

2005-09-07 Thread nephish
oh wait.
never mind , i figgured it out!
thanks anyway

-- 
http://mail.python.org/mailman/listinfo/python-list


need to divide a date

2005-09-22 Thread nephish
Hey there,
i am doing a plotting application.
i am using mxRelativeDateTimeDiff to get how much time is between
date x and date y

now what i need to do is divide that time by 20 to get 20 even time
slots
for plotting on a graph.

For example, if the difference between them is 20 hours, i need 20
plots, each an hour apart. if its 40 minutes, i need 20 plots that are
2 minutes apart.

what would be a way i could pull this off?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


time challenge

2005-09-22 Thread nephish

Hey there,
i am doing a plotting application.
i am using mxRelativeDateTimeDiff to get how much time is between
date x and date y

now what i need to do is divide that time by 20 to get 20 even time
slots
for plotting on a graph.

For example, if the difference between them is 20 hours, i need 20
plots, each an hour apart. if its 40 minutes, i need 20 plots that are
2 minutes apart.

what would be a way i could pull this off?

thanks


-- 
http://mail.python.org/mailman/listinfo/python-list


check to see if value can be an integer instead of string

2006-01-17 Thread nephish
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 an integer.

like this

var = some var passed to my script
if var can be an integer :
do this
else:
change it to an integer and do something else with it.

whats the best way to do this ?

thanks, shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: check to see if value can be an integer instead of string

2006-01-17 Thread nephish
thanks for the reply, but wont python fail out if you try to make an
integer out of what cant be an integer?
like this :

var = int(abc)

wont this crash ?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: check to see if value can be an integer instead of string

2006-01-17 Thread nephish
this looks like the solution i am looking for. thanks for the education
by the way.
i have a couple of other try / except clauses. Never thought of pulling
it off like that.
thanks very much, really simple.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: check to see if value can be an integer instead of string

2006-01-18 Thread nephish
it isn't really that i will want to change it to an integer anyway. the
script uses a table to reference a value to a key, if the key is a
group of letters, that code tells the script to do something. if the
value is a number, it means an equipment failure. The thing is, all the
values come out as strings (they are read from a text file).
so what you put first with the try/except looks like my best answer.

thanks,
shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


how to know if socket is still connected

2006-07-16 Thread nephish
lo there,
i have a simple app that connects to a socket to get info from a server

i looks like this

serverhost = 'xxx.xxx.xxx.xxx'
serverport = 9520
aeris_sockobj = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
aeris_sockobj.connect((serverhost,serverport))

while 1:
do this or that with socket,
send and receive info.
yadda yadda yadda


works well, but sometimes the server drops the connection.
so, what i need is something that will let me know if the connection
is still ok, if not will reconnect.

what i thought, since it only lets you connect on a certain port one at
a time,
that i could use a try-except to connect every time, if it could not
connect (because it already is) then i would just continue on. But if
it is not connected, it would reconnect.
that is what brings me here. Seems like it would work, but is there a
better way ? this kinda seems like a dirty hack.

any opinions ?

thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to know if socket is still connected

2006-07-16 Thread nephish

Grant Edwards wrote:
> On 2006-07-16, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > serverhost = 'xxx.xxx.xxx.xxx'
> > serverport = 9520
> > aeris_sockobj = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> > aeris_sockobj.connect((serverhost,serverport))
> >
> > while 1:
> > do this or that with socket,
> > send and receive info.
> > yadda yadda yadda
> >
> > works well, but sometimes the server drops the connection. so,
> > what i need is something that will let me know if the
> > connection is still ok, if not will reconnect.
>
> If the server has closed the connection, then a recv() on the
> socket will return an empty string "", and a send() on the
> socket will raise an exception.
>
> > what i thought, since it only lets you connect on a certain
> > port one at a time, that i could use a try-except to connect
> > every time, if it could not connect (because it already is)
> > then i would just continue on. But if it is not connected, it
> > would reconnect. that is what brings me here. Seems like it
> > would work, but is there a better way?
>
> I don't see why the normal send() and recv() semantics aren't
> sufficient.
>
> --
> Grant Edwards   grante Yow!  I'm an East Side
>   at   TYPE...
>visi.com



like this ?
databack = aeris_sockobj.recv(2048)
 if databack:
view_msg = 'caught request acknowlage %s bytes \n' %
len(databack)
else:
view_msg = 'fail to recieve data from aeris server\n'

then put the reconnect in the else: block ?

thanks


thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cool Python Ebooks Site

2006-07-16 Thread nephish
are not most (or all) of these copywrite protected ?
thats why i have not pulled some of them myself,
you can get most of them used from amazon for
about $10


[EMAIL PROTECTED] wrote:
> http://cooldogebooks.blogspot.com/2006/05/python-ebooks.html
>
> Here is a cool site were you can preview python ebooks.
>
> Here are just a few listed
>
> Advanced_Python_programming.pdf 20-Oct-2004 14:23 194K
> EP2003CppExtensions.pdf 20-Oct-2004 14:25 2.0M
> GUI Programming with Python.zip 20-Oct-2004 14:36 16M
> Game_Programming_with_Python.pdf 20-Oct-2004 14:26 67K
> How_To_Think_Like_A_Computer_Scientist-Learning_With_Python-2002.pdf
> 20-Oct-2004 14:37 863K
> How_to_think_like_a_computer_scientist.pdf 20-Oct-2004 14:36 720K
> New Riders - Jython for Java Programmers.chm 20-Oct-2004 14:38 713K
> OReilly - Core Python Programming.pdf 20-Oct-2004 14:43 7.8M
> OReilly - Learning Python.chm 20-Oct-2004 14:44 967K
> OReilly - Programming Python 2nd Ed.chm 20-Oct-2004 14:48 6.4M
> OReilly - Python & XML.pdf 20-Oct-2004 14:49 2.0M
> OReilly - Python Cookbook.chm 20-Oct-2004 14:49 1.0M
> OReilly - Python Developer's Handbook.rar 20-Oct-2004 14:50 1.6M
> OReilly - Python In A Nutshell eBook-LiB.chm 20-Oct-2004 14:51 1.1M
> OReilly - Python Programming on Win32.chm 20-Oct-2004 14:52 2.1M
> OReilly - Python Standard Library.chm 20-Oct-2004 14:52 356K
> Python???rar 20-Oct-2004 16:09 64M
> Python.pdf 20-Oct-2004 14:59 391K
> Python 2.1 Bible.pdf 20-Oct-2004 14:58 6.3M
> Python Essential Reference, Second Edition.rar 20-Oct-2004 14:58 536K
> Python Pocket Reference.chm 20-Oct-2004 14:59 175K
> PythonWindowsTutorial.doc 20-Oct-2004 16:10 1.9M
> Python_Programming_with_the_JavaT_Class_Libraries_-_Addison_Wesley_-_2002.chm
> 20-Oct-2004 15:00 1.8M CD-ROM
> Sams - Teach Yourself Python In 24 Hours.rar 20-Oct-2004 15:52 2.4M
> Thinking in python.chm 20-Oct-2004 14:21 178K
> an-introduction-to-tkinter.pdf 20-Oct-2004 14:23 733K
> diveintopython-pdf-4.3.zip 20-Oct-2004 14:24 519K
> iconcrib.pdf 20-Oct-2004 14:37 152K
> icongraphics.pdf 20-Oct-2004 14:37 138K
> mailgate/ 26-Oct-2004 02:27 -
> modpython.pdf 20-Oct-2004 14:38 164K
> pil-handbook.pdf 20-Oct-2004 14:53 486K
> pil.pdf 20-Oct-2004 14:53 232K
> portal.tar.gz 20-Oct-2004 14:53 45K tar xvfz filename
> pygtk2tutorial.tar.gz 20-Oct-2004 14:54 1.6M tar xvfz filename
> pygtk2tutorial.tgz 20-Oct-2004 14:54 775K tar xvfz filename
> pyref_cn.zip 20-Oct-2004 14:55 314K
> pyscponly.py 20-Oct-2004 14:55 815
> pyshell.txt 20-Oct-2004 14:55 1.1K
> python_wdsl.pdf 20-Oct-2004 15:00 134K
> python network programming.pdf 20-Oct-2004 14:59 309K ?ยง
> tkinter.chm 20-Oct-2004 14:21 315K
> tkinter.pdf 20-Oct-2004 14:22 415K
> tutorial python.pdf 20-Oct-2004 14:22 268K
> Advanced_Python_programming [miex.org].pdf
> An Introduction to Tkinter.chm
> Dive into Python [miex.org].pdf
> GUI_Programming_with_Python_-_QT_Edition [miex.org].chm
> Game Scripting in Python [miex.org].doc
> How_To_Think_Like_A_Computer_Scientist-Learning_With_Python-2002
> [miex.org].pdf
> How_to_think_like_a_computer_scientist [miex.org].pdf
> Instant_Hacking_With_Python [miex.org].zip
> New Riders - Jython for Java Programmers [miex.org].chm
> New Riders - Python Essential Reference, 2Nd Ed - 2001 [miex.org].chm
> OReilly - Core Python Programming [miex.org].pdf
> OReilly - Learning Python ed2 [miex.org].chm
> OReilly - Programming Python ed2 [miex.org].chm
> OReilly - Python & XML [miex.org].pdf
> OReilly - Python In A Nutshell [miex.org].chm
> OReilly - Python Pocket Reference,2001 ed2 [miex.org].chm
> OReilly - Python Programming on Win32 [miex.org].chm
> OReilly - Python Standard Library [miex.org].chm
> Preiss,_B.R._-_Data_Structures_and_Algorithms_in_Python_(2004)
> [miex.org].chm
> Premier.Press,.Python.Programming.for.the.Absolute.Beginner.(2003).LiB.ShareConnector
> [miex.org].chm
> Prentice Hall - Core Python Programming (Fixed).chm
> Python network programming.pdf
> Python[1].Cookbook.2nd.chm
> Python_2.1_bible_(idg_2001)_[pdf] [miex.org].zip
> Python_Developer's_Handbook_(2000) [miex.org].chm
> Race_Evolution_Behavior.pdf
> Sams - Teach Yourself Python In 24 Hours.rar
> SciTE editor for Python
> Scientific Computing in Python [miex.org].pdf
> Text_Processing_in_Python_(Addison_Wesley-2003) [miex.org].chm
> Thinking in Python [miex.org].chm
> VIM editor for Python
> mec.Python Programming with the Java Class Libraries.2002
> [miex.org].chm
> modpython [miex.org].pdf
> numpy_tutorial [miex.org].pdf
> python-doc-2.4.chm
> skip4Python [miex.org].chm
> OReilly - Learning Python 17-Dec-2005 04:49
> OReilly - Programming Python 2nd Ed 17-Dec-2005 04:50
> Oreilly.Learning.Python.2nd.Edition.eBook-LiB 17-Dec-2005 04:53
> Oreilly.Python.In.A.Nutshell.eBook-LiB 17-Dec-2005 04:58
> Sams - Teach Yourself Python In 24 Hours 17-Dec-2005 05:43
> Thinking in python 17-Dec-2005 05:43
> dive in to python 17-Dec-2005 04:46
> instant-hacking.php 17-Dec-2005 04:47
> Advanced_Python_programming.pdf  28-Apr-2004 16:36  194K
> Bourne S

Re: how to know if socket is still connected

2006-07-16 Thread nephish
cool enough, thanks !

-sk


Grant Edwards wrote:
> On 2006-07-16, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> >> If the server has closed the connection, then a recv() on the
> >> socket will return an empty string "", and a send() on the
> >> socket will raise an exception.
>
> > like this ?
> > databack = aeris_sockobj.recv(2048)
> >  if databack:
> > view_msg = 'caught request acknowlage %s bytes \n' %
> > len(databack)
> > else:
> > view_msg = 'fail to recieve data from aeris server\n'
> >
> > then put the reconnect in the else: block ?
>
> Yes, if the problem is that the host closes the connection,
> that should work.  Modulo the broken indentation and
> line-wrapping. ;)
>
> --
> Grant Edwards   grante Yow!  My mind is a potato
>   at   field...
>visi.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to know if socket is still connected

2006-07-17 Thread nephish
hey there, i have a question about this solution.
if i have a
message = socket.recv()
in the script, and the socket connection drops, will the
socket.recv() just wait forever for something to come across
the internet port? or will it know if the connection is dropped?
thanks.
-sk


Grant Edwards wrote:
> On 2006-07-17, Cameron Laird <[EMAIL PROTECTED]> wrote:
>
> >>> works well, but sometimes the server drops the connection. so,
> >>> what i need is something that will let me know if the
> >>> connection is still ok, if not will reconnect.
> >>
> >>If the server has closed the connection, then a recv() on the
> >>socket will return an empty string "", and a send() on the
> >>socket will raise an exception.
> >>
> >>> what i thought, since it only lets you connect on a certain
> >>> port one at a time, that i could use a try-except to connect
> >>> every time, if it could not connect (because it already is)
> >>> then i would just continue on. But if it is not connected, it
> >>> would reconnect. that is what brings me here. Seems like it
> >>> would work, but is there a better way?
> >>
> >>I don't see why the normal send() and recv() semantics aren't
> >>sufficient.
> > .
> > .
> > .
> > Often normal send() and recv() semantics have been mistaught.
> > An alert alien, looking at other common APIs in isolation,
> > might reasonably wonder whether there is some sort of
> > still_ok_to_use() sort of check as part of TCP.  As it happens,
> > of course, that doesn't fit with the rest of socket networking,
> > which takes the "modernist" approach of trying send() or recv(),
> > and reporting any exception.
>
> On most Unices there are some obscure API features that can be
> used to generate a SIGPIPE under some vaguely specified error
> conditions (e.g. TCP keepalive timeout).  I've only read about
> them and never tried to use them, since I couldn't see anything
> in the description of the features that was any benefit over
> the nomral send() and recv() usage.
>
> --
> Grant Edwards   grante Yow!  Xerox your lunch
>   at   and file it under "sex
>visi.comoffenders"!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to know if socket is still connected

2006-07-17 Thread nephish
oh, sorry, what i mean by dropped is that the server i am connecting to
can close the connection. If that happens, i need to know about it.
i also need to know about it if the server i am connecting to just
dies.

if recv() returns "" is that the same as NONE ?
again, sorry, i am still kinda new at this.
I mean can the value be tested true or false?

thanks
-sk


Grant Edwards wrote:
> On 2006-07-17, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > hey there, i have a question about this solution.
> > if i have a
> > message = socket.recv()
> > in the script, and the socket connection drops, will the
> > socket.recv() just wait forever for something to come across
> > the internet port? or will it know if the connection is dropped?
>
> As I said before, if the socket is closed by the remote host,
> recv() will return "".
>
> I don't know what you mean by "drops" and "dropped" in this
> context.  If you want a useful answer to your question, you'll
> have to define your terms precisely.
>
> --
> Grant Edwards   grante Yow!  I'm CONTROLLED by
>   at   the CIA!! EVERYONE is
>visi.comcontrolled by the CIA!!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to know if socket is still connected

2006-07-17 Thread nephish
> If the server _application_ crashes or exits, then the OS will
> close the socket and recv() will return "".  If somebody powers
> down the server without warning, or if the server OS crashes,
> or if the Ethernet cable between the Internet and the server is
> cut, then the socket will not be closed, and recv() will wait
> forever[1].

Ok, yes all of the above is what i mean. Actually I am not too
concerned about a server os crash, or the cable being cut. But I have
had them close the connection on me, after which i just reconnect
(whenever i discover that its happened)

>[1] Unless you've enabled the TCP Keepalive feature, in which
> case the socket will timeout in a couple hours and recv()
> will return "".

if this is something that must be enabled, or is not enabled by
default, then it is not enabled.
so i should be pretty good.

thanks for all of your help, gents !
-sk




Grant Edwards wrote:
> On 2006-07-17, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > oh, sorry, what i mean by dropped is that the server i am
> > connecting to can close the connection.
>
> Then recv() will return "" and send() will raise an exception.
>
> > If that happens, i need to know about it. i also need to know
> > about it if the server i am connecting to just dies.
>
> Again, you have to define what you mean by "server just dies".
>
> If the server _application_ crashes or exits, then the OS will
> close the socket and recv() will return "".  If somebody powers
> down the server without warning, or if the server OS crashes,
> or if the Ethernet cable between the Internet and the server is
> cut, then the socket will not be closed, and recv() will wait
> forever[1].
>
> > if recv() returns "" is that the same as NONE ?
>
> No.  It's the empty string (also spelt '').
>
> > I mean can the value be tested true or false?
>
> Yes.  The empty string is false, all non-empty strings are
> true.
>
> [1] Unless you've enabled the TCP Keepalive feature, in which
> case the socket will timeout in a couple hours and recv()
> will return "".
>
> --
> Grant Edwards   grante Yow!  Now I am depressed...
>   at
>visi.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to know if socket is still connected

2006-07-17 Thread nephish
ok, yeah, thats in my book.
thanks, and no, it isn't enabled.
thanks again for everything
-sk


Grant Edwards wrote:
> On 2006-07-17, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >> If the server _application_ crashes or exits, then the OS will
> >> close the socket and recv() will return "".  If somebody powers
> >> down the server without warning, or if the server OS crashes,
> >> or if the Ethernet cable between the Internet and the server is
> >> cut, then the socket will not be closed, and recv() will wait
> >> forever[1].
> >
> > Ok, yes all of the above is what i mean. Actually I am not too
> > concerned about a server os crash, or the cable being cut. But I have
> > had them close the connection on me, after which i just reconnect
> > (whenever i discover that its happened)
> >
> >>[1] Unless you've enabled the TCP Keepalive feature, in which
> >>case the socket will timeout in a couple hours and recv()
> >>will return "".
> >
> > if this is something that must be enabled, or is not enabled by
> > default, then it is not enabled.
>
> On all OSes with which I'm familiar it's disabled by default.
> You use a socket object's setsockopt method to enable it:
>
> s.setsockopt(socket.SOL_TCP,socket.SO_KEEPALIVE,True)
>
> --
> Grant Edwards   grante Yow!  Wow! Look!! A stray
>   at   meatball!! Let's interview
>visi.comit!

-- 
http://mail.python.org/mailman/listinfo/python-list


question about what lamda does

2006-07-17 Thread nephish
Hey there,
i have been learning python for the past few months, but i can seem to
get what exactly a lamda is for. What would i use a lamda for that i
could not or would not use a def for ? Is there a notable difference ?
I only ask because i see it in code samples on the internet and in
books.

thanks for any clarity

sk

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about what lamda does

2006-07-18 Thread nephish
ok, i think i get it.
pretty cool.
thanks
-sk


Dan Bishop wrote:
> [EMAIL PROTECTED] wrote:
> > Hey there,
> > i have been learning python for the past few months, but i can seem to
> > get what exactly a lamda is for.
>
> It defines a function.
>
> f = lambda x, y: expression
>
> is equivalent to
>
> def f(x, y):
>return expression
>
> Note that lambda is an expression while def is a statement.
>
> > What would i use a lamda for that i
> > could not or would not use a def for ? Is there a notable difference ?
> > I only ask because i see it in code samples on the internet and in
> > books.
>
> Lambdas are typically used as parameters to functions that take
> functions as arguments, like property() and reduce().  You never *need*
> to use one, but sometimes it's convenient.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about what lamda does

2006-07-18 Thread nephish
so a lamda needs to stay at one expression, and use more than one lamda
for more expressions ?

i think i get it.

sk

Nick Vatamaniuc wrote:
> Use it anywhere a quick definition of a function is needed that can be
> written as an expression. For example when a callback function is
> needed you could say:
> def callback(x,y):
>   return x*y
> some_function(when_done_call_this=callback)
> But with lambda you could just write
> some_function(when_done_call_this=lambda x,y:x*y)
> Note: because it is an _expression_ you cannot do stuff like 'if..else'
> inside of lambda.
>
> -Nick V.
>
> [EMAIL PROTECTED] wrote:
> > Hey there,
> > i have been learning python for the past few months, but i can seem to
> > get what exactly a lamda is for. What would i use a lamda for that i
> > could not or would not use a def for ? Is there a notable difference ?
> > I only ask because i see it in code samples on the internet and in
> > books.
> > 
> > thanks for any clarity
> > 
> > sk

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about what lamda does

2006-07-20 Thread nephish
hey thanks for that last post, although some of it was a bit over my
head.
i think i am getting more of the differences here.

thanks again,
sk

danielx wrote:
> [EMAIL PROTECTED] wrote:
> > Hey there,
> > i have been learning python for the past few months, but i can seem to
> > get what exactly a lamda is for. What would i use a lamda for that i
> > could not or would not use a def for ? Is there a notable difference ?
> > I only ask because i see it in code samples on the internet and in
> > books.
> >
> > thanks for any clarity
> >
> > sk
>
> hehe. Lambda's are kind of a sensative subject for pythoners who come
> from Lisp. Guido being more of a C guy doesn't really like them, and
> thought they should be removed in py3k. Last time I checked, he was
> reconsidering because of public outcry, presumably from the Lisp crowd.
>
> The standard reason for getting rid of it is "anywhere you need a
> lambda, you can use a def". In addition to what has been said here,
> there is another one small difference between lambda's and functions,
> which is that when you use def, the object gets a name:
>
> >>> def foo(): pass
> ...
> >>> foo
> 
> # ^ foo knows its own name
> >>> bar
> 
> # ^ see ;)
> >>>
>
> Whereas, a lambda has no name; it's "anonymous":
>
> >>> spam = lambda: 1
> >>> spam
>  at 0x009D80F0>
> # ^ spam has an identity crisis ;)
> >>>
>
> Many people who do not come from Lisp do not understand what the use of
> a lambda is (and I have no idea what the purpose of having a name is).
> Even people who do question whether it belongs in Python. In Lisp,
> lambda's are the way things get done, because you can calculate
> anything using just defines and expressions. This style does not fit
> Python very well, since we do things using statements.
>
> Python's lambda really can't be as powerful as Lisp's because Python
> does not have expressions that do case analysis (this is not lambda's
> fault, of course ;). The reason is that you really want to put each
> case on its own set of lines. This enhances readability at the expense
> of terseness. Since Python's statements are terminated by a newline, it
> would be rather awkward to have a kind of expression where good style
> calls for it to be spread out accross multiple lines.
>
> You can try to simulate these kinds expressions using into a list or
> dictionary, but this becomes rather messy. I think the only way to get
> this done properly is to use eval. For example:
>
> def recursiveFunction(args):
>   ...  # do stuff...
>   choices = { True:"0", False:"recurisveFunction(newArgs)" }
>   return eval( choices[predicate] )
>
> The reason that you need eval is that you want to prevent any cases
> from being executed until you decide which one you want. This stay of
> execution is accomplished by wrapping quotes around our expressions.
> This example illustrates why we really need this kind of behavior,
> because without it, we would fall into an infinite loop. Even if it
> were safe to evaluate all cases, it's a big waste of time to do so.
>
> Lastly, I think there is also a performance concern for certain uses of
> lambda (correct me if I'm wrong). Say you have an expression with a
> lambda in it where you could have used a def. Every time you evaluate
> that expression, you have to construct a new lambda object, which takes
> time. If you had used a def instead, you could hav avoided having to
> construct multiple times.

-- 
http://mail.python.org/mailman/listinfo/python-list


prob with struct and byte order

2006-07-24 Thread nephish
hello there, all.

i have a difficult app that connects to a server to get information for
our database here.
this server is our access point to some equipment in the field that we
monitor.

the messages come in over a socket connection. And according to their
(very limited) documentation, are set up in a particular order. like
this

STX [length indicator] [message type] [message body] ENX

length indicator = length of the message body in 4 bytes
message type = the code for what type of message is being sent
   for example 200 = login
message body = the actual command to send to the server

STX and ENX are the values assigned to start and stop a message.
they are literally 'STX' and 'ENX'


when i capture a message i can print it to the screen and the 'STX' at
the beginning and the 'ENX' at the end are discernable, but the rest of
the message looks like this..

\x00\x00\x00,\x00\x00\x00\e17758\x00\x00   and so on and so forth...
with some commas and other symbols in there. (the e before the 17758
has a little hat on it)
 If i print it out to a text file, i get this...
STXNULNULNULea17758NULLNULL etc..

now the 17758 is significant because it is the actual unit number of
the machine we want to monitor. I just dont know how to extract the
real values out of this message.

anyone have an idea where to start? i have experimented with struct,
but do not know enough about it. Does anyone know a good tutorial about
learning byte codes and such. The docs on pythons website explain the
module well, but i still do not know what to do with it. Or how to
generate a message or pull apart these values to get a message out of
what the server sends us. 

thanks
sk

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: prob with struct and byte order

2006-07-24 Thread nephish
ok, i did this print ' '.join(["%02.2x" % ord(b) for b in message])
and i got this in the text file
535458002c00ea31373538343636383535d6090d54454e58
so, yes, more of the info seems discernable now.

according to their docs, all of their variables are sent as 32bit long
int (prefferably unsigned long int).

the developers at the server we are trying to talk to have released an
api for C (maybe C++) that comes in an osx module that one is supposed
to import into visual basic. I am not developing in visual basic, or
windows or C or C++. So my challenge is to get some of the same
functionality  out of python on debian linux.

the osx module is what they give out to developers who have apps that
need to talk with this server.

the starting and ending deliminators are ASCII 'STX' and 'ENX'. i
wondered why they did it like that also. But they did.

the message length is a 4 byte integer indicating how long the message
body is.
the message type is also 4 bytes. There is a table in the docs that
describe what each message type is. for example 200 = login,
etc...etc...

the big deal in the docs goes on about how the clients need the byte
order to match that of the arch that the server runs on 'Sun
UltraSPARC' , i think they run Solaris.

if i sound like i do not know what i am talking about... there is a
reason...  i am very new to this type of communication with the server.
I have about 6 months with python ( my first language ).

thanks for your help, gents .

-sk
Grant Edwards wrote:
> On 2006-07-24, Steve Holden <[EMAIL PROTECTED]> wrote:
> > [EMAIL PROTECTED] wrote:
> >> hello there, all.
> >>
> >> i have a difficult app that connects to a server to get information for
> >> our database here.
> >> this server is our access point to some equipment in the field that we
> >> monitor.
> >>
> >> the messages come in over a socket connection. And according to their
> >> (very limited) documentation, are set up in a particular order. like
> >> this
> >>
> >> STX [length indicator] [message type] [message body] ENX
> >>
> >> length indicator = length of the message body in 4 bytes
> >> message type = the code for what type of message is being sent
> >>for example 200 = login
> >> message body = the actual command to send to the server
> >>
> >> STX and ENX are the values assigned to start and stop a message.
> >> they are literally 'STX' and 'ENX'
>
> > I believe you, but this is clearly a perversion of the
> > single-character "start of transmission" and "end of
> > transmission" that are part of the ASCII alphabet. So the
> > protocol designer may have been inexperienced, and the
> > documentation may be confused ...
>
> I had the same reaction: surely he means the frame is delmited
> at the beginning by the ASCII STX character (0x02) and the end
> by the ETX character (0x03).
>
> If somebody is indeed sending the three character string "STX"
> to mark the beginning of a frame and "ENX" to mark the end,
> then they're seriously confused (and can't spell).
>
> >> when i capture a message i can print it to the screen and the 'STX' at
> >> the beginning and the 'ENX' at the end are discernable, but the rest of
> >> the message looks like this..
> >>
> >> \x00\x00\x00,\x00\x00\x00\e17758\x00\x00   and so on and so forth...
> >> with some commas and other symbols in there. (the e before the 17758
> >> has a little hat on it)
>
> So the unit number is an ASCII string.  Firstly, I'd recommend
> printing the message in hex:
>
> print ' '.join(["%02.2x" % ord(b) for b in message])
>
> That should make it easier to figure how which byte indexes
> contain the info you're looking for.
>
> >> If i print it out to a text file, i get this...
> >> STXNULNULNULea17758NULLNULL etc..
>
> I'm a but baffled how the string shown above would get printed
> like that.
>
> > The "\x00" is the Python repr() of a single-byte string containing a
> > null byte (i.e. a byte whose decimal value is zero).
> >
> >> now the 17758 is significant because it is the actual unit number of
> >> the machine we want to monitor. I just dont know how to extract the
> >> real values out of this message.
>
> What is meant by "real values"?
>
> >> anyone have an idea where to start? i have experimented with
> >> struct, but do not know enough about it. Does anyone know a
> >> good tutorial about learning byte codes and such.
>
> What are "byte codes"?
>
> >> The docs on pythons website explain the module well, but i
> >> still do not know what to do with it.
>
> You've got to figure out the format and location within the
> message of the objects you care about.  Once you know that, you
> use struct to pull out the appropriate bytes and convert them
> into Python objects.
>
> If you know (or suspect) there are IEEE 754 32-bit floating
> point values in the message, then start converting all of the
> possible 4-byte chunks into Python floats (using both endian
> conventions) until you see numbers you re

Re: prob with struct and byte order

2006-07-24 Thread nephish
ok. indeed i did do '' instead of ' '.
here is an example of a message
'STX\x00\x00\x004\x00\x00\x00\xc8stateman\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00state1man\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00ENX'

tohex gave me '53 54 58 00 00 00 34 00 00 00 c8 70 69 76 6f 74 72 61 63
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 74 72 61 63 31 70 69 76
6f 74 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 4e 58'

this is the login message (message type 200)

i will try out your code sample when i get to work in the morning.

thanks, gents, for your time and attention on this

sk

John Machin wrote:
> Grant Edwards wrote:
> > On 2006-07-24, Steve Holden <[EMAIL PROTECTED]> wrote:
> > > [EMAIL PROTECTED] wrote:
> > >
> > >> now the 17758 is significant because it is the actual unit number of
> > >> the machine we want to monitor. I just dont know how to extract the
> > >> real values out of this message.
> >
> > What is meant by "real values"?
> >
>
> :-)
> I guess he means "real" as opposed to unreal/surreal/virtual/imagined,
> not as in the FORTRAN programmer's credo:
> """
> GOD is REAL
> JESUS is INTEGER
> """
> (-:

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: prob with struct and byte order

2006-07-25 Thread nephish
ok. here is how i got a message in the first place. The data server
developers released this one windows app that simulates a real app. In
that it logs into the server and sends and receives commands. instead
of putting in the data servers ip though, i put in the ip address of
the linux box i am building this on. when a command got sent, i had a
listening socket open that would receive the command from the
simulation program and dump it into a mysql table. So far its worked
becuase the same command works with the real server. But now, i have to
learn how to contruct messages for real because of the control we want
to have over the field units.

i put this in

def split_message(message):
if not (message.startswith('STX') or message.endswith('ENX')):
raise ValueError('missing start or end sequence')
length, message_type = struct.unpack('>II', message[3:11])
return length, message_type, message[11:-3]

print 'length: %d\ntype: %d\n%r' % split_message(data)

and this is what was in the txt file. ( i am using a text file for
sys.stdout becuase my terminal app does not do copy and paste.)

length: 52
type: 200
'stateman\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00stat1manet\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

i used the same snippit for a query message
length: 44
type: 234
'1758466855\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd6\t\rT\x00\x00\x00\x00'

now, the message type 234 is correct according to the docs. Here is
what it has to say.
query_ANSI:
used to request information about a particular data system in the field
unsigned long int messageType = 234;
unsigned char  primaryMIN(32);  # this is the serial number of
the unit
unsigned long int ESN # serial number of the communicator
unsigned long int userID


thanks again guys.. i think we're getting closer.

-sk

John Machin wrote:
> Marc 'BlackJack' Rintsch wrote:
> > In <[EMAIL PROTECTED]>, nephish wrote:
> >
> > > tohex gave me
> > > '53 54 58
> >
> >S  T  X
> >
> > > 00 00 00 34
> >
> > Length!?  Decimal 57.
>
> 3 * 16 + 4 -> 52 where I come from -- assuming hex means hexadecimal
> and not witchcraft :-)
>
> >
> > > 00 00 00 c8
> >
> > Type!?  Decimal 200.
> >
> > > 70 69 76 6f 74 72 61 63 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
> > > 74 72 61 63 31 70 69 76 6f 74 00 00 00 00 00 00 00 00 00 00 00 00 00 00
> >
> > Payload!?
> >
> > > 45 4e 58'
> >
> >   E  N  X
> >
> > > this is the login message (message type 200)
> >
> >
> > The problem I see is the length.  The payload without STX, ENX and the two
> > numbers in front is 47 bytes so there's a 5 byte difference.
>
> I don't think so.
>
> >  You have to
> >  look at some more messages to get an idea how the length corresponds to
> >  the actual payloads length.
>
> Yes, but not because of the 5-difference problem. The OP has favoured
> us with 3 messages (in 3 different formats), 2 x login and 1 of some
> sort of data. See below.
>
> 8<--- script start
> import struct
>
> def unhex(s, spaced):
> return ''.join([chr(int(s[x:x+2], 16)) for x in xrange(0, len(s), 2
> + spaced)]) # gasp
>
> hex1 =
> "535458002c00ea31373538343636383535d6090d54454e58"
> txt1 = unhex(hex1, 0)
>
> txt2 =
> 'STX\x00\x00\x004\x00\x00\x00\xc8stateman\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00state1man\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00ENX'
>
>
> hex3 = '53 54 58 00 00 00 34 00 00 00 c8 70 69 76 6f 74 72 61 63 00 00
> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 74 72 61 63 31 70 69 76 6f 74
> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 4e 58'
> txt3 = unhex(hex3, 1)
>
> for msgno, msg in enumerate((txt1, txt2, txt3)):
> print "\nMessage %d: length of actual string is %d" % (msgno + 1,
> len(msg))
> print "Has STX/ENX:", msg.startswith("STX") and msg.endswith("ENX")
> print "repr:", repr(msg)
> print "hex :", ' '.join(["%02x" % ord(x) for x in msg])
> msg_len, msg_type = struct.unpack('>II', msg[3:11])
> print "Internal len: %d; type: %d" % (msg_len, msg_type)
> 8<--- end script, start output
>
> Message 1: length of actual string is 54
> Has STX/ENX: True
> repr:
> 'STX\x00\x00\x00,\x00\x00\x00\xea1758466855\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x

easy question about join method

2006-08-06 Thread nephish
i have seen the join method before, mostly in this group and i want to
get it a little better.

if i have a list

x = ['this','is','a','sentence','held','in','a','list']

how can i make it print as a single string? or make a single string out
of it ?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question about join method

2006-08-06 Thread nephish
yep, easy enough

thanks

-shawn


Jorge Godoy wrote:
> "nephish" <[EMAIL PROTECTED]> writes:
>
> > i have seen the join method before, mostly in this group and i want to
> > get it a little better.
> >
> > if i have a list
> >
> > x = ['this','is','a','sentence','held','in','a','list']
> >
> > how can i make it print as a single string? or make a single string out
> > of it ?
> 
> print ' '.join(x)
>  
> -- 
> Jorge Godoy  <[EMAIL PROTECTED]>

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question about join method

2006-08-06 Thread nephish
very helpful indeed.
i did a help([]) to see if it would give me anything for a list.
wow.
thanks a lot.

-sk

Terry Reedy wrote:
> The easy way to get one answer for buildin funcs and methods is the help
> function in the interactive interpreter (and Idle's and probably other
> imitations thereof) is, for example,
>
> >>> help(str.join)
> Help on method_descriptor:
>
> join(...)
> S.join(sequence) -> string
>
> Return a string which is the concatenation of the strings in the
> sequence.  The separator between elements is S.
>
> To remind how to use 'help', 'help' is more informative than 'help(help)'
> ;-)
> 
> Terry Jan Reedy

-- 
http://mail.python.org/mailman/listinfo/python-list


question about class, functions and scope

2006-08-26 Thread nephish
lo there all,

i have an app that runs three classes as threads in the same program.
some of them need to be able to share some functions. Can i set a
function before i define a class and have the class use it ? Kinda like
this.

def some_function(var1, var2):
do something with var1, var2
return result

class do_something1(threading.Thread):
def __init__(var):
do something
def run():
var1 = 3
var2 = 4
result = some_function(var1,var2)

is this legal ? is it pythonic?
i ask because i plan to do a big re-write soon, and want to get rid of
some repetition

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about class, functions and scope

2006-08-26 Thread nephish

[EMAIL PROTECTED] wrote:
> nephish:
> > is this legal ? is it pythonic?
>
> It's legan and pythonic. Functions are here for a purpose.
>
> Bye,
> bearophile

cool enough, and thanks for the quick reply.

shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about class, functions and scope

2006-08-26 Thread nephish

nephish wrote:
> [EMAIL PROTECTED] wrote:
> > nephish:
> > > is this legal ? is it pythonic?
> >
> > It's legan and pythonic. Functions are here for a purpose.
> >
> > Bye,
> > bearophile
>
> cool enough, and thanks for the quick reply.
>
> shawn

one more question.
the functions defined above the classes that the could be called from
within the classes, they do not need a 'self' declaration because they
are not part of a class, right?

sk

-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >