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


need help with converting c function to python function

2007-07-05 Thread nephish
hello all,

i have a c function from some modbus documentation that i need to
translate into python.

it looks like this:


unsigned short CRC16(puchMsg, usDataLen)
unsigned char *puchMsg ;
unsigned short usDataLen ;
{
   unsigned char uchCRCHi = 0xFF ;
   unsigned char uchCRCLo = 0xFF ;
   unsigned uIndex ;
   while (usDataLen--)
   {
   uIndex = uchCRCHi ^ *puchMsgg++ ;
   uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex} ;
   uchCRCLo = auchCRCLo[uIndex] ;
   }
   return (uchCRCHi << 8 | uchCRCLo) ;
}

some of it i can make out, but i can't seem to figgure out
this part ' auchCRCHi[uIndex};
it looks like a typo, because there is a closing } that does not match
the opening [.


here is what i have so far, but is not giving me the right values

 def crc16(data):
 crc_hi = 0xff
 crc_lo = 0xff
 for x in data:
 crc_index = crc_hi ^ x
 crc_hi = crc_lo ^ (crc_hi | crc_index)
 crc_lo = crc_lo | crc_index
 return (crc_hi << 8 | crc_lo)

whaddya think?

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:
> > 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?
>
> Class methods generally require the self as first parameter, functions
> don't need the self. So your original code was wrong (sorry, I haven't
> seen that before).
>
> You can also inject functions as methods inside a class, and in such
> case your function usually needs a self parameter too.
>
> Bye,
> bearophile

ok, thanks much, thats all i needed to know.
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


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


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: 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


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


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: 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

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-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

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: 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


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-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


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: 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


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
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
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-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: 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

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


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: problem with writing a simple module

2006-05-24 Thread nephish
cool, thanks, i was running on some thinner examples i found on the
net.

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


Re: problem with writing a simple module

2006-05-23 Thread nephish
ok, what i posted above had the getOne method, the whole class has a
function for getMany, update, and Insert.

none of this will be used by an end user, it kinda runs in the
background. But, if you have a good link to the docs on the API, i
would like to see it. Still kinda new at this.

thanks

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


Re: problem with writing a simple module

2006-05-23 Thread nephish
ok, thanks everyone. The funny thing about the name conventions is, i
was just two days ago looking around on the web for the best way to go
about consistancy in variable names, class names, etc..

i have the module working now. thanks to you guys. And i think i
understand the container name | object name paradigm.

i did not get the suggestion to change all my database queries so the
parameter substitution is performed by the .execute*() methods..

that one went over me head.

thanks for all the help, guys

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


Re: problem with writing a simple module

2006-05-22 Thread nephish
yeah, i have thought of picking that one up. That one, or nutshell.
i got programming python, which was way over my head, then learning
python, which has helped me a great deal.

thanks

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


Re: problem with writing a simple module

2006-05-22 Thread nephish
ok, cool, and thanks very much. That worked.
thanks for the info too.
i am still new at the OO thing, just tired of doing a copy and paste
over and over again.

thanks again

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


problem with writing a simple module

2006-05-22 Thread nephish
ello there. i am having a problem getting a module to work right.

i wrote a class that is going to be used in a few different scripts in
the same directory.

it looks like this:

#!/usr/bin/python

import MySQLdb

class DbConnector(object):
"""
Database Connection object.
class receives the db argument to specify the database.
"""

def __init__(self, db='test_db', host="10.10.10.16",user="me",
passwd="mypass"):
self.host   =   host
self.user   =   user
self.passwd =   passwd
self.db = db
# Unpack Other Database Arguments Here
self.CreateConnection()

def createConnection(self):
self.connection = MySQLdb.connect(self.host, self.user, 
self.passwd,
self.db)

def killConnection(self):
self.connection.close()

def getMany(self, sql_statement):
cursor = self.connection.cursor()
try:
cursor.execute(sql_statement)
result = cursor.fetchall()
self.connection.close()
return result
except:
self.connection.close()

the file is saved as DbConnector.py and made executable.
then i get this in idle

>> import DbConnector
>> x = DbConnector()

then it tells me that the module object is not callable.

this works though
>> import DbConnector
>> x = DbConnector
>> x.db = 'other_db'
>> results = x.getOne("SELECT * FROM `stuff`")

it tells me that the module has no attribute getOne.

i am really not trying for an attribute, but a method.

anyone know what i am doing wrong?

thanks

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


Re: can i set up a mysql db connection as a class ?

2006-04-28 Thread nephish
way cool, i think that this will work.

thanks very much

-sk

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


Re: can i set up a mysql db connection as a class ?

2006-04-28 Thread nephish
So this opens and closes the connection every time i run the query?
thats cool. i think that would fit in well. so when i need to run the
query, i pass something like

query = "SELECT * FROM `Table` WHERE `foo` = 'bar'"

result = DB_Connector.Execute(query)

and the result would be the same as if i ran the query right there in
the thread?

thanks for all your help gents, this is helping me a lot.

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


Re: can i set up a mysql db connection as a class ?

2006-04-27 Thread nephish
This is great !

ok, i dont really have a lot of time to get into the ORMS (before your
post, this is the first i have heard of it) and my stuff is due on
Monday. he he.

but, if i am able to make a global db connection, and multiple cursors
pointing to the same connection object, how do i pull that off without
making new db connections?

something like
class db(self):
def __init__(self):
  db = MySQLdb.connect(host="localhost", user="MyUser",
 passwd="MyPassword",
db="Stuff")
def cursor(self):
  cursor = db.cursor()
  return cursor


then have in my threads that need to connect

cursor = db.cursor()
cursor2 = db.cursor()

and so on ? i may be way outta whack here. i am still new at classes,
methods, and modules.
i do have Essential Reference on the way from Amazon though ! :)

thanks again

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


can i set up a mysql db connection as a class ?

2006-04-27 Thread nephish
hey there,
i have a huge app that connects to MySQL. There are three threads that
are continually connecting and disconnecting to the db. The problem is,
if there is an error, it faults out sometimes without closing the
connection. i connect like this.
db = MySQLdb.connect(host="localhost", user="MyUser",
passwd="MyPassword", db="Stuff")
cursor=db.cursor()

then i use the cursor.execute("SELECT yadda yadda

my question is, is there a way i can set up a global connection so that
when the program loads, it connects once, then stays connected ? maybe
i could assign instances of the cursor ?

please someone let me know if you have any good ideas

sk

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


Re: need a thread to keep a socket connection alive?

2006-04-25 Thread nephish
yeah, he he

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


Re: need a thread to keep a socket connection alive?

2006-04-24 Thread nephish
ok, every message starts with "ENX" and ends with "STX"
in between are several parts. the first is the message length sent as
an unsigned long int (according to the docs) this is four bytes. The
next is the message type - another 4 bytes that corrospond to a certain
chart. for example, the login is message type 200. Then there is the
message. different messages have different lengths and types.
the data part, i am still trying to break apart. Some of it (when
printed to the screen) is a string, then some very funny characters,
then another string, then more funny looking characters, then 'ETX'

up untill now, all i have had to process is the strings, so i split the
message up, and used the strings as my data. But now, i do need the
other info. -whew.

i guess i am learning a lot. i just ordered Python Essential Reference
from amazon. ;)

anyway. from what i have found on line, i am going to be using the
struct module.



oh, that was a typo earlier. not 34 bytes, but 14.
the data comming in is alway in 158 bytes though.

thanks guys.

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


Re: need a thread to keep a socket connection alive?

2006-04-24 Thread nephish
ok, thanks for all the suggestions, gents, i clearly have more to read
on this.
i have discovered that the server will send a request for the heartbeat
ping if its almost timed out, so i use the length of the message to
determine what to do with it.

msg = sockobj.recv(1024)

if len(msg) == 158:
record the data
elif len(msg) == (34): # length of request for ping
ping the server
else:
yada yada.

each real message ( according to their docs ) should be exactly 158
bytes.

i know i need to look more into all of this.. but thanks for all of
your help

-shawn

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


Re: need a thread to keep a socket connection alive?

2006-04-22 Thread nephish
thanks for the info, i will likely use the first link you posted with
the async module just to get it going, but i want to learn more about
twisted for later. there is even an O'Reilly book on it i see.
thanks for the tips,
sk

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


need a thread to keep a socket connection alive?

2006-04-22 Thread nephish
hey there,

i have a script that waits for message packets from a data server over
a socket.
it goes a little like this:

while 1:
x+=1
databack = sockobj.recv(158)
if databack:

print 'caught a message %s bytes ' % len(databack)
if len(databack) > 120:
message = databack[3:-3] #strip stx and enx
print '\n\n%s' % message
else:
   break
print 'end data ack'


it works fine for a while, but the server requires that i send a
heartbeat ping every 600 seconds or it will terminate the connection.

so i also need something like
while 1:
 sockobj.send(ping)
 ping_acknowlage = sockobj.recv(48)
 time.sleep(550)



should i do this with threads? i dont want to interrupt the listening
cycle to send a ping.

appreciate any tips on how would be the best way to pull this off.

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


Re: another question about buffers

2006-04-22 Thread nephish
i think it may be,
i am just doing a while 1: loop to just wait for whatever comes in.
thanks

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


another question about buffers

2006-04-21 Thread nephish
lo there all !

i finally got my script to receive info on a socket. but i need to
somehow set up a loop that will continue to listen for more info
comming across the same socket.

the way it works is, i log in with a login and password, it shoots back
an acknowlagement, then i send a request for data. every so often it
will send a packet of data that i need to record. i know how to receive
once, but i dont know how to go back to receive again.

the messages all start with "STX" and end with "ETX"

here is what i have so far. (it isn't working very well)

#set a socket to communicate with the server
serverhost = '10.10.10.4'
serverport = 9550

print 'connecting to server'
sockobj = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockobj.connect((serverhost,serverport))
login = 'STXusernamepasswordETX'
sockobj.send(login)
login_ack = sockobj.recv(1028)
if login_ack:
print 'received login_ack'
else:
print 'login failure'



req = "STXsendreqETX"
sockobj.send(req) # send request for data stream

databack = sockobj.recv(1028)
if databack:
print 'caught a message %s bytes ' % len(databack)
else:
print 'fail to recieve data from server'

the output in the terminal runs fine until it fails to get the
databack, it prints out the "fail to receive from server" bit.

anything obvious that i am missing here?

thanks

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


Re: freakin out over C++ module in python

2006-04-20 Thread nephish
sounds cool, most stuff i write is strife with try - except

thanks for the tip

-sk

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


Re: freakin out over C++ module in python

2006-04-19 Thread nephish
wow , thanks for the tips and the link.. i can at least see whats going
on here.
this project is beginning to look believable to me.

i have another question.. later , in this same class, after it goes
thru some error handling, it returns like this
return COM_SUCCESS;
but i cannot find where COM_SUCCESS is defined.
can something in C++ just represent itself?

thanks again for all your help.

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


Re: freakin out over C++ module in python

2006-04-18 Thread nephish
pyconstruct looks cool. i dont know if the classes are using the plain
berkely-ish code. i couldn't find anything in it that pointed to send()
recv(), & such. i found other stuff like SetSocketOpt() and so on like
this :

long CClientSocket::ConnectToServer(LPCTSTR serverAddr, UINT port)

{

BOOL socketOption = TRUE;

const int rcvBuffsize = 64 *1024;

const int sendBuffsize = 64*1024;



if ( !Create() )

return ERR_SOCKET_CREATE;

int intvalue = sizeof(int);

if(!( SetSockOpt(SO_DONTROUTE,&socketOption,sizeof(BOOL),SOL_SOCKET)
&&

SetSockOpt(SO_RCVBUF,&rcvBuffsize,sizeof(int),SOL_SOCKET) &&

SetSockOpt(SO_SNDBUF,&sendBuffsize,sizeof(int),SOL_SOCKET) &&

SetSockOpt(TCP_NODELAY,&socketOption,sizeof(BOOL),SOL_SOCKET) &&

SetSockOpt(SO_KEEPALIVE,&socketOption,sizeof(BOOL),SOL_SOCKET)))

return ERR_SOCKET_CREATE;


i looked around for some of these and found most references to UDP. I
guess its also a windows specific thing too. thanks for the tips
gents

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


Re: freakin out over C++ module in python

2006-04-18 Thread nephish
ok, well enough, looked at struct and it does seem to be what i am
after. for that anyway.
thanks, guess i will just have to take the time and pull it apart.

cheers
sk

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


freakin out over C++ module in python

2006-04-17 Thread nephish
lo there all !

i have a huge delima, i have to be able to connect to a data server and
recieve info from it. The servers software guys release some visual C++
modules that one can incorporate into a visual C++ project. Which is
great, but i am developing in linux, and only am very familliar with
python. i have tried to use swig to make a python module out of it, and
it wouldn't work. Tried to just compile them with gcc and that would
not work either. So, i have to go thru and try to re-create them in
python. So here is the trick, i don't know anything about C++, but this
has got to work.


and so, i guess the main question i have is is there a module or
program that will parse these classes and duplicate them for a python
module ? Some kind of code translator ? Or is that just way out there?

i would go thru it line by line, but i just dont know enough about C++,
how it pulls off a socket connection, etc.. and some of the things i
dont know how to do in python. like how to make an unsigned long init.

whew. so, i guess i could google each line... but if someone has an
easier alternative, i am all ears.. its about 400 lines total.

thanks.
sk

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


Re: need a start point for wsdl

2006-03-06 Thread nephish
cool, thank you very much

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


need a start point for wsdl

2006-03-06 Thread nephish
hello there, i have recently been tasked with grabbing info to pipe
into our database from an information server. The server guys told me i
need to grab their wsdl file. Untill earlier this afternoon, i had no
idea what wsdl is. From what i gather, it is much like SOAP.
So anyway, any pythoneers out there make use of this? Know of some good
documentation or even a book ? i would appreciate very much a good
start point to begin learning how to pull this off.
thanks

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


Re: in over my head ascii

2006-02-07 Thread nephish
indeed i did not. thanks for the tip.

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


Re: in over my head ascii

2006-02-07 Thread nephish
ok, i am stuck again.

from the docs, the byte stream is supposed to look like this:

'S' 'T' 'X'   [length indicator] [message type] [message] 'E' 'N' 'X'

the length indicator it says is a four byte integer number of a value N
 ( N would be how long the message body is )

the message type comes from a table in the docs. In my case, the
message type is 200. This is also supposed to be sent as  a 4 byte
value.

so. how do i make 200 occupy 4 bytes ?

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


Re: in over my head ascii

2006-02-07 Thread nephish
i'm not sure, but its kinda been a pain in the hinder for a newbie like
me to find it in their docs.
thanks for all the help guys, let you know how it goes

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


Re: in over my head ascii

2006-02-06 Thread nephish
i know that those characters exist, the docs say that the server does
not want the special "ETX" and "STX" characters, but the 3 ascii
characters "STX" and "ENX" i am not sure why.

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


Re: in over my head ascii

2006-02-06 Thread nephish
ok, part of what i have to do is know how many bytes will be sent. in
ascii is it one byte per character ?
like "password" would be 8 bytes long?

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


Re: in over my head ascii

2006-02-06 Thread nephish
i think like byte 1 = 'S'
byte 2 = 'T'
and byte 3 = 'X'

still new at this, and thanks for the references

-sk

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


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

2006-02-06 Thread nephish
Thanks guys,
No, i did not know about isdigit ?
very helpful. Thanks.

esp liked the "overloaded doohicky' bit.

thanks again.

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


in over my head ascii

2006-02-06 Thread nephish
Hello there,
i need to write a script that can transfer info back and forth with a
data server at so-and-so ip.

i have Programming Python, which covers socket programming. So thats
cool. But what i need to know how to do is make a message in ascii that
is what the server is looking for.

for example , to send a request, the first three bytes have to be ascii
"STX"
then there has to be  4 bytes that show the length of the message
then the actual message
then the last three bytes have to be "ENX"

also all int variables must me unsigned long-int (32 bit).

so here is what i need to know,
1 how do i make something in ascii bytes to send off to this server ?
2 how can i make sure something is a 32bit unsigned long int. ?

If the answers i am looking for are pretty straightforward, please let
me know., If they are long and complicated, please point me to some
good documentation . 

thanks for all,
sk

-- 
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


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-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


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: 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


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


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: 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


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


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: 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


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


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: 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


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: 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


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


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: 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


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
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
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-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-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-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
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 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-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-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
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


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: 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


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


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: another time challenge

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

-- 
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


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


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


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


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


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


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


  1   2   >