using smtp sent large file upto 60MB

2012-12-04 Thread moonhkt
Hi All

How to using python send file uptp 60MB ?


s = smtplib.SMTP("localhost")
#~~ s.set_debuglevel(1)
s.sendmail(from_addr, to_addr,m.as_string())
s.quit


For 13MB file have below error
s.sendmail(from_addr, to_addr,m.as_string())
  File "/opt/freeware/lib/python2.6/email/message.py", line 135, in
as_string
g.flatten(self, unixfrom=unixfrom)
  File "/opt/freeware/lib/python2.6/email/generator.py", line 84, in
flatten
self._write(msg)
  File "/opt/freeware/lib/python2.6/email/generator.py", line 119, in
_write
self._fp.write(sfp.getvalue())
MemoryError: out of memory
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conversion of List of Tuples

2012-12-04 Thread Gary Herron

On 12/03/2012 11:58 AM, [email protected] wrote:

[(1,2), (3,4)]

>>> L=[(1,2), (3,4)]
>>>
>>> [b   for a in L   for b in a]
[1, 2, 3, 4]


--
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

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


Re: how to split the file into two sections....

2012-12-04 Thread Peter Otten
[email protected] wrote:

> Hi:
> I have a text as
> version comp X - aa
> version comp Y - bbb
> version comp Z -cc
> 
> 12.12 Check for option 1
> 
> 12:13 Pass Test 1
> 12:14 verified bla bla bla
> 12.15 completed
> 
> 12.16 Fail Test 2
> 12:17 verified bla bla bla
> 12.18 completed
> 
> 12.19 Fail Test 3
> 12:20 verified bla bla bla
> 12.21 completed
> 
> 12.22 Check for option B
> 
> 12:23 Pass Test4
> 12:24 verified bla bla bla
> 12.25 completed
> 
> 12.26 Fail Test 5
> 12:27 verified bla bla bla
> 12.28 completed
> 
> 12.29 Fail Test 6
> 12:30 verified bla bla bla
> 12.31 completed
> 
>  In this I want to split the file to two sections to post the summary as
> 
> Check for option 1
> Pass 2
> Fail 1
> Check for option 2
> Pass 2
> Fail 1

Open the file
Iterate over the lines
Extract the second word
If it's "Check" print the current stats (if any) and remember the 
line
If it's "Fail" increase a fail counter
If it's "Pass" increase a fail counter
Print the current stats (if any)

[Optional] Come back here for help with the details once you have some code.

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


Re: Conversion of List of Tuples

2012-12-04 Thread Alexander Blinne
Am 03.12.2012 20:58, schrieb [email protected]:
> Dear Group,
> 
> I have a tuple of list as,
> 
> tup_list=[(1,2), (3,4)]
> Now if I want to covert as a simple list,
> 
> list=[1,2,3,4]
> 
> how may I do that?

Another approach that has not yet been mentioned here:

>>> a=[(1,2), (3,4)]
>>> b=[]
>>> map(b.extend, a)
[None, None]
>>> b
[1, 2, 3, 4]

map returns [None, None] because extend returns nothing, but now
b==[1,2,3,4].

There are more ways:

>>> from operator import add
>>> reduce(add, a)
(1, 2, 3, 4)

or

>>> reduce(operator.add, (list(t) for t in a))
[1, 2, 3, 4]

I didn't do any performance testing, i guess the first one should be
about as fast es the for-loop approach with .extend() and the other two
might be quite slow. Although this only really matters if you have large
lists.

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


Re: using smtp sent large file upto 60MB

2012-12-04 Thread Chris Angelico
On Tue, Dec 4, 2012 at 7:15 PM, moonhkt  wrote:
> How to using python send file uptp 60MB ?

Step one: Don't. SMTP is almost never the best choice for sending huge
files around.

There are plenty of other ways to share files; send an email with
instructions on how to access the file, rather than attaching the
file. For general consumption, the easiest way is usually to include a
URL for HTTP download. If it's something internal, you might want to
put the file on a shared-access FTP server or file share.

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


scope, function, mutable

2012-12-04 Thread gusarer
Hi,

What is the appropriate definition for the following behavior in Python 2.7
(see code below).
Both functions have assignment in it (like "x = ") so I assume, that x is a
local variable in both functions.
Also I thought this rule doesn't depend on WHERE in this function we find
the assignment.

But in both functions x becomes local variable only AFTER assignment, so in
f2 x[1] = 99 changes the global varialble (btw, x[3] = 99 doesn't).

def f1(x):
x = [44] + x[1:]
x[1] = 99

def f2(x):
x[1] = 99
x = [44] + x[1:]
x[3] = 99

t = [1,2,3,4,5,6,7]
f1(t)
print t# [1, 2, 3, 4, 5, 6, 7]
t = [1,2,3,4,5,6,7]
f2(t)
print t# [1, 99, 3, 4, 5, 6, 7]

Thank you.

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


CSV out of range

2012-12-04 Thread Anatoli Hristov
Hello,

I tried to read a CSV file with 3 products in it and index it into
a list using

file = open("ShopPrices.csv", "rbU")
reader = csv.reader(file, delimiter=";")
mylist = []

for x in reader:
mylist.append(x)

The problem comes when I try to index the SKU array and the field is empty

for sku in mylist:
print sku[3]

after the 3060 result I'm getting an error:

IndexError: list index out of range

and it seems that there I have empty array, I wanted to ignore the
empty arrays using if statement, but it does the same.

Thanks

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


Re: CSV out of range

2012-12-04 Thread Thomas Bach
Hi there,

Please be a bit more precise…

On Tue, Dec 04, 2012 at 12:00:05PM +0100, Anatoli Hristov wrote:
> 
> The problem comes when I try to index the SKU array and the field is
> empty

Can you provide an example for that?

> and it seems that there I have empty array, I wanted to ignore the
> empty arrays using if statement, but it does the same.

Please provide a small, runable example with the actual code you tried
that raises the exception and the complete trace back.

Regards,
Thomas Bach.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: scope, function, mutable

2012-12-04 Thread Steven D'Aprano
On Tue, 04 Dec 2012 14:55:44 +0400, gusarer wrote:

> What is the appropriate definition for the following behavior in Python
> 2.7 (see code below).
> Both functions have assignment in it (like "x = ") so I assume, that x
> is a local variable in both functions.

Well, yes, but that's not why x is local in this case. In this case, x is 
local because the name of the function parameter is "x", and function 
parameters are always local.



> Also I thought this rule doesn't depend on WHERE in this function we
> find the assignment.
> 
> But in both functions x becomes local variable only AFTER assignment, 

Not so. Read on.

> so
> in f2 x[1] = 99 changes the global varialble (btw, x[3] = 99 doesn't).
> 
> def f1(x):
> x = [44] + x[1:]
> x[1] = 99

When you call f1(t), with t a global list, Python passes the list object 
to the function and binds it to name x. The function gets executed like 
this pseudo-code:

# calling f1(t)
pass object known as "t" to the function
bind that object to the local name "x"
create a new list: [44] + a slice of x
bind this new list to name "x"
modify in place item 1 of the new list known as "x"


Notice that the only *modification* occurs after a new list is created 
and bound to the name "x", so the modification does not change the 
original, global, list.


But now consider your other function:

> def f2(x):
> x[1] = 99
> x = [44] + x[1:]
> x[3] = 99

In pseudo-code again:

# calling f2(t)
pass object known as "t" to the function
bind that object to the local name "x"
modify in place item 1 of the list known as "x", 
which is another name for the global list known as "t"
create a new list: [44] + a slice of x
bind this new list to name "x"
modify in place item 3 of the new list known as "x"

So in this case you have to in-place modifications. The first occurs 
while the name "x" still refers to the original list, and so it modifies 
the original list. The second occurs after the name "x" has been rebound 
to a new list, and so it doesn't change the original.



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


Re: scope, function, mutable

2012-12-04 Thread Thomas Bach
Hi,

On Tue, Dec 04, 2012 at 02:55:44PM +0400, [email protected] wrote:
> What is the appropriate definition for the following behavior in Python 2.7
> (see code below).

It has something to do with mutability of lists and that Python passes
around references and not the actual objects.

> 
> def f1(x):
> x = [44] + x[1:]
> x[1] = 99
> 
> def f2(x):
> x[1] = 99
> x = [44] + x[1:]
> x[3] = 99
> 
> t = [1,2,3,4,5,6,7]
> f1(t)
> print t# [1, 2, 3, 4, 5, 6, 7]
> t = [1,2,3,4,5,6,7]
> f2(t)
> print t# [1, 99, 3, 4, 5, 6, 7]

Put that code in e.g. file.py and run

python -m pdb file.py

this will drop you off in the debugger. Step through your code line by
line (using ‘s’) and see how the function calls affect your list
(e.g. via ‘print x’/‘print t’). If this confuses you further… Well,
tell me that my autodidact methodology did not work out at all and ask
again. ;)

Regards,
Thomas.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conversion of List of Tuples

2012-12-04 Thread Hans Mulder
On 4/12/12 10:44:32, Alexander Blinne wrote:
> Am 03.12.2012 20:58, schrieb [email protected]:
>> Dear Group,
>>
>> I have a tuple of list as,
>>
>> tup_list=[(1,2), (3,4)]
>> Now if I want to covert as a simple list,
>>
>> list=[1,2,3,4]
>>
>> how may I do that?
> 
> Another approach that has not yet been mentioned here:
> 
 a=[(1,2), (3,4)]
 b=[]
 map(b.extend, a)
> [None, None]
 b
> [1, 2, 3, 4]
> 
> map returns [None, None] because extend returns nothing, but now
> b==[1,2,3,4].

It's considered bad style to use map it you don't want the list it
produces.

> There are more ways:
> 
 from operator import add
 reduce(add, a)
> (1, 2, 3, 4)

There's a built-in that does "reduce(operator.add"; it's called "sum":

>>> sum(a, ())
(1, 2, 3, 4)
>>>
> or
> 
 reduce(operator.add, (list(t) for t in a))
> [1, 2, 3, 4]

This is a valid use case for the map operator:

>>> sum(map(list, a), [])
[1, 2, 3, 4]
>>>

> I didn't do any performance testing, i guess the first one should be
> about as fast as the for-loop approach with .extend() and the other two
> might be quite slow. Although this only really matters if you have large
> lists.

Hope this helps,

-- HansM



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


Re: scope, function, mutable

2012-12-04 Thread Jussi Piitulainen
[email protected] writes:

> What is the appropriate definition for the following behavior in
> Python 2.7 (see code below).
>
> Both functions have assignment in it (like "x = ") so I assume, that
> x is a local variable in both functions.

It's a local variable in both functions because it's a formal
parameter in both. The assignments don't make any difference
here. (And a statement like x[k] = ... never does.)

> Also I thought this rule doesn't depend on WHERE in this function we
> find the assignment.

That's correct but not relevant here. It's relevant when the variable
does not occur in the function's parameter list.

> But in both functions x becomes local variable only AFTER
> assignment, so in f2 x[1] = 99 changes the global varialble (btw,
> x[3] = 99 doesn't).

In both functions, x is local from the start. Its initial value is the
same mutable object that is the value of the global variable t. The
assignments x = [44] ... give it a new value, another mutable object,
but x[k] = ... don't. The latter make a change in the old value which
is still the value of the globale variable t.

> def f1(x):
> x = [44] + x[1:]
> x[1] = 99
> 
> def f2(x):
> x[1] = 99
> x = [44] + x[1:]
> x[3] = 99
> 
> t = [1,2,3,4,5,6,7]
> f1(t)
> print t# [1, 2, 3, 4, 5, 6, 7]
> t = [1,2,3,4,5,6,7]
> f2(t)
> print t# [1, 99, 3, 4, 5, 6, 7]

You might want to consider something like the following, because the
point really has everything to do with the fact that mutable objects
are not copied when they are passed to functions, assigned to
variables, or stored somewhere like a list, and little to do with
global vs local (other than there being different variables with the
same name).

t = [1,2,3]
u = [1,2,3]
w = u
w[1] = 0
u = t

Some people will tell you to use different words but the behaviour of
the language doesn't change.
-- 
http://mail.python.org/mailman/listinfo/python-list


[newbie] problem with usbtmc-communication

2012-12-04 Thread Jean Dubois
The following test program which tries to communicate with a Keithley
2200 programmable power supply using usbtmc in Python does not work as
expected. I have connected a 10 ohm resistor to its terminals and I
apply 0.025A, 0.050A, 0.075A en 0.1A,
I then measure the current and the voltage en write them in a file
De data produced looks like this:
0.00544643 0.254061; first current value is wrong, voltage value is
correct
0.0250807 0.509289; second current value is wrong, but it corresponds
to the first, second voltage is correct
0.0501099 0.763945; 3rd current value is wrong, but it corresponds to
the second, 3rd voltage is right
0.075099 1.01792; 4th current value is wrong,  it corresponds to the
3rd, 4th voltage is right
4th correct current value is missing

But is should be (numerical inaccuracy taking into account)(these data
were produced by a similar octave-program):
0.0248947 0.254047
0.0499105 0.509258
0.0749044 0.764001
0.0998926 1.01828

Here is the python-program:
#!/usr/bin/python
import time
import os
import sys
measurementcurr=''
measurementvolt=''
timesleepdefault=1
filename ='mydata.txt'
usbkeith = open('/dev/usbtmc1','r+')
usbkeith.flush()
usbkeith.write("*IDN?\n")
#strip blank line:
identification=usbkeith.readline().strip()
print 'Found device: ',identification
usbkeith.write("SYST:REM" + "\n")
usbkeith.write(":SENS:VOLT:PROT 1.5\n")
keithdata = open(filename,'w')
#start first measurement
usbkeith.write(":SOUR:CURR 0.025\n")
usbkeith.write(":OUTP:STAT ON\n")
time.sleep(timesleepdefault)
usbkeith.write(":MEAS:CURR?\n")
time.sleep(timesleepdefault)
measurementcurr=usbkeith.readline()
print 'Measured current 1: ',measurementcurr
usbkeith.write("MEAS:VOLT?\n")
time.sleep(timesleepdefault)
measurementvolt=usbkeith.readline()
print 'Measured voltage 1: ',measurementvolt
keithdata.write(measurementcurr.strip()+' '+measurementvolt)
#start second measurement
usbkeith.write("SOUR:CURR 0.050\n")
time.sleep(timesleepdefault)
usbkeith.write("MEAS:CURR?\n")
time.sleep(timesleepdefault)
measurementcurr=usbkeith.readline()
print 'Measured current 2: ',measurementcurr
usbkeith.write("MEAS:VOLT?\n")
time.sleep(timesleepdefault)
measurementvolt=usbkeith.readline()
print 'Measured voltage 2: ',measurementvolt
keithdata.write(measurementcurr.strip()+' '+measurementvolt)
#start 3rd measurement
time.sleep(timesleepdefault)
usbkeith.write("SOUR:CURR 0.075\n")
time.sleep(timesleepdefault)
usbkeith.write("MEAS:CURR?\n")
time.sleep(timesleepdefault)
measurementcurr=usbkeith.readline()
print 'Measured current 3: ',measurementcurr
usbkeith.write("MEAS:VOLT?\n")
time.sleep(timesleepdefault)
measurementvolt=usbkeith.readline()
print 'Measured voltage 3: ',measurementvolt
keithdata.write(measurementcurr.strip()+' '+measurementvolt)
#start 4th measurement
time.sleep(timesleepdefault)
usbkeith.write("SOUR:CURR 0.1\n")
time.sleep(timesleepdefault)
usbkeith.write("MEAS:CURR?\n")
time.sleep(timesleepdefault)
measurementcurr=usbkeith.readline()
print 'Measured current 4: ',measurementcurr
usbkeith.write("MEAS:VOLT?\n")
time.sleep(timesleepdefault)
measurementvolt=usbkeith.readline()
print 'Measured voltage 4: ',measurementvolt
keithdata.write(measurementcurr.strip()+' '+measurementvolt)
usbkeith.write(":OUTP:STAT OFF\n")
print "Goodbye, data logged in file:"
print filename
usbkeith.close()
keithdata.close()

can anyone here what is going wrong and how to get it right?

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


Re: CSV out of range

2012-12-04 Thread Anatoli Hristov
On Tue, Dec 4, 2012 at 12:31 PM, Thomas Bach
 wrote:
> Hi there,
>
> Please be a bit more precise…
>
> On Tue, Dec 04, 2012 at 12:00:05PM +0100, Anatoli Hristov wrote:
>>
>> The problem comes when I try to index the SKU array and the field is
>> empty
>
> Can you provide an example for that?
>
>> and it seems that there I have empty array, I wanted to ignore the
>> empty arrays using if statement, but it does the same.
>
> Please provide a small, runable example with the actual code you tried
> that raises the exception and the complete trace back.
>
> Regards,
> Thomas Bach.
> --
> http://mail.python.org/mailman/listinfo/python-list

Ok as I said I run a small script, here it is:

>>> import csv
>>>
>>> file = open("ShopPrices.csv", "rbU")
>>> reader = csv.reader(file, delimiter=";")
>>> mylist = []
>>> for i in reader:
... mylist.append(i)
...
>>> mylist[543]
['19ITN992575', '19I', 'TN', '992575', 'RAB-UP-750-H3', 'Triton 19"
heavy duty 150kg shelf plate 750mm 1U black', '39,93', '0', '', '',
'', '', '', '', '', '', '', '', '']
>>> sku = []
>>> for x in mylist:
... sku.append(x[4])
...
Traceback (most recent call last):
  File "", line 2, in ?
IndexError: list index out of range

>>> sku[43]
'PDM2332IEC-3P30R-3'
>>>

It appends all the data till it comes one SKU with empty record ("") .
I tried to use tey and except, but still the same

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


Re: CSV out of range

2012-12-04 Thread Anatoli Hristov
The issue is now solved I did:

for x in mylist:
try:
sku.append(x[4])
except IndexError:
pass

Thank you for your help

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


Re: Conversion of List of Tuples

2012-12-04 Thread Neil Cerutti
On 2012-12-04, Hans Mulder  wrote:
> It's considered bad style to use map it you don't want the list it
> produces.
>
>> There are more ways:
>> 
> from operator import add
> reduce(add, a)
>> (1, 2, 3, 4)
>
> There's a built-in that does "reduce(operator.add"; it's called "sum":
>
 sum(a, ())
> (1, 2, 3, 4)

I thought that sort of thing would cause a warning. Maybe it's
only for lists.

Here's the recipe from the itertools documentation:

def flatten(listOfLists):
"Flatten one level of nesting"
return chain.from_iterable(listOfLists)

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


Re: CSV out of range

2012-12-04 Thread Neil Cerutti
On 2012-12-04, Anatoli Hristov  wrote:
> The issue is now solved I did:
>
> for x in mylist:
> try:
> sku.append(x[4])
> except IndexError:
> pass
>
> Thank you for your help

Optionally:

for x in mylist:
if len(x) >= 4:
sku.append(x[4])

But do you really need to save the whole file in a list first?
You could simply do:

for record in csvreader:
  if len(record) >= 4:
  sku.append(record[4])

Or even:

sku = [record[4] for record in csvreader if len(record) >= 4]

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


Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Neil Cerutti
On 2012-12-04, Nick Mellor  wrote:
> I have a file full of things like this:
>
> "CAPSICUM RED fresh from Queensland"
>
> Product names (all caps, at start of string) and descriptions
> (mixed case, to end of string) all muddled up in the same
> field. And I need to split them into two fields. Note that if
> the text had said:
>
> "CAPSICUM RED fresh from QLD"
>
> I would want QLD in the description, not shunted forwards and
> put in the product name. So (uncontrived) list comprehensions
> and regex's are out.
>
> I want to split the above into:
>
> ("CAPSICUM RED", "fresh from QLD")
>
> Enter dropwhile and takewhile. 6 lines later:
>
> from itertools import takewhile, dropwhile
> def split_product_itertools(s):
> words = s.split()
> allcaps = lambda word: word == word.upper()
> product, description = takewhile(allcaps, words), dropwhile(allcaps, 
> words)
> return " ".join(product), " ".join(description)
>
> When I tried to refactor this code to use while or for loops, I
> couldn't find any way that felt shorter or more pythonic:

I'm really tempted to import re, and that means takewhile and
dropwhile need to stay. ;)

But seriously, this is a quick implementation of my first thought.

description = s.lstrip(string.ascii_uppercase + ' ')
product = s[:-len(description)-1]

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


Re: [newbie] problem with usbtmc-communication

2012-12-04 Thread wrw
On Dec 4, 2012, at 7:14 AM, Jean Dubois  wrote:

> The following test program which tries to communicate with a Keithley
> 2200 programmable power supply using usbtmc in Python does not work as
> expected. I have connected a 10 ohm resistor to its terminals and I
> apply 0.025A, 0.050A, 0.075A en 0.1A,
> I then measure the current and the voltage en write them in a file
> De data produced looks like this:
> 0.00544643 0.254061; first current value is wrong, voltage value is
> correct
> 0.0250807 0.509289; second current value is wrong, but it corresponds
> to the first, second voltage is correct
> 0.0501099 0.763945; 3rd current value is wrong, but it corresponds to
> the second, 3rd voltage is right
> 0.075099 1.01792; 4th current value is wrong,  it corresponds to the
> 3rd, 4th voltage is right
>4th correct current value is missing
> 
> But is should be (numerical inaccuracy taking into account)(these data
> were produced by a similar octave-program):
> 0.0248947 0.254047
> 0.0499105 0.509258
> 0.0749044 0.764001
> 0.0998926 1.01828
> 
> Here is the python-program:
> #!/usr/bin/python
> import time
> import os
> import sys
> measurementcurr=''
> measurementvolt=''
> timesleepdefault=1
> filename ='mydata.txt'
> usbkeith = open('/dev/usbtmc1','r+')
> usbkeith.flush()
> usbkeith.write("*IDN?\n")
> #strip blank line:
> identification=usbkeith.readline().strip()
> print 'Found device: ',identification
> usbkeith.write("SYST:REM" + "\n")
> usbkeith.write(":SENS:VOLT:PROT 1.5\n")
> keithdata = open(filename,'w')
> #start first measurement
> usbkeith.write(":SOUR:CURR 0.025\n")
> usbkeith.write(":OUTP:STAT ON\n")
> time.sleep(timesleepdefault)
> usbkeith.write(":MEAS:CURR?\n")
> time.sleep(timesleepdefault)
> measurementcurr=usbkeith.readline()
> print 'Measured current 1: ',measurementcurr
> usbkeith.write("MEAS:VOLT?\n")
> time.sleep(timesleepdefault)
> measurementvolt=usbkeith.readline()
> print 'Measured voltage 1: ',measurementvolt
> keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> #start second measurement
> usbkeith.write("SOUR:CURR 0.050\n")
> time.sleep(timesleepdefault)
> usbkeith.write("MEAS:CURR?\n")
> time.sleep(timesleepdefault)
> measurementcurr=usbkeith.readline()
> print 'Measured current 2: ',measurementcurr
> usbkeith.write("MEAS:VOLT?\n")
> time.sleep(timesleepdefault)
> measurementvolt=usbkeith.readline()
> print 'Measured voltage 2: ',measurementvolt
> keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> #start 3rd measurement
> time.sleep(timesleepdefault)
> usbkeith.write("SOUR:CURR 0.075\n")
> time.sleep(timesleepdefault)
> usbkeith.write("MEAS:CURR?\n")
> time.sleep(timesleepdefault)
> measurementcurr=usbkeith.readline()
> print 'Measured current 3: ',measurementcurr
> usbkeith.write("MEAS:VOLT?\n")
> time.sleep(timesleepdefault)
> measurementvolt=usbkeith.readline()
> print 'Measured voltage 3: ',measurementvolt
> keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> #start 4th measurement
> time.sleep(timesleepdefault)
> usbkeith.write("SOUR:CURR 0.1\n")
> time.sleep(timesleepdefault)
> usbkeith.write("MEAS:CURR?\n")
> time.sleep(timesleepdefault)
> measurementcurr=usbkeith.readline()
> print 'Measured current 4: ',measurementcurr
> usbkeith.write("MEAS:VOLT?\n")
> time.sleep(timesleepdefault)
> measurementvolt=usbkeith.readline()
> print 'Measured voltage 4: ',measurementvolt
> keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> usbkeith.write(":OUTP:STAT OFF\n")
> print "Goodbye, data logged in file:"
> print filename
> usbkeith.close()
> keithdata.close()
> 
> can anyone here what is going wrong and how to get it right?
> 
> thanks
> jean
> -- 
> http://mail.python.org/mailman/listinfo/python-list

Just guessing here - it looks as though you are setting the current and THEN 
turning the output on.  That might be the correct sequence or it might not.  If 
not, it would explain the offset between that and the subsequent readings.

This is really a Keithley problem, not a Python problem.

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


Re: CSV out of range

2012-12-04 Thread Anatoli Hristov
On Tue, Dec 4, 2012 at 2:58 PM, Neil Cerutti  wrote:
> On 2012-12-04, Anatoli Hristov  wrote:
>> The issue is now solved I did:
>>
>> for x in mylist:
>> try:
>> sku.append(x[4])
>> except IndexError:
>> pass
>>
>> Thank you for your help
>
> Optionally:
>
> for x in mylist:
> if len(x) >= 4:
> sku.append(x[4])
>
> But do you really need to save the whole file in a list first?
> You could simply do:
>
> for record in csvreader:
>   if len(record) >= 4:
>   sku.append(record[4])
>
> Or even:
>
> sku = [record[4] for record in csvreader if len(record) >= 4]
>
> --
> Neil Cerutti

Thanks Neil,

I'm still testing it - just trying to clean the things out and be sure
that I can do all of the stuff :)

I will create a list only of the products I have in the DB and will
compare them for prices stock etc... so the list will be smaller :)

Thanks again

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


Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Nick Mellor
Hi Neil,

Nice! But fails if the first word of the description starts with a capital 
letter.

Nick


On Wednesday, 5 December 2012 01:23:34 UTC+11, Neil Cerutti  wrote:
> On 2012-12-04, Nick Mellor  wrote:
> 
> > I have a file full of things like this:
> 
> >
> 
> > "CAPSICUM RED fresh from Queensland"
> 
> >
> 
> > Product names (all caps, at start of string) and descriptions
> 
> > (mixed case, to end of string) all muddled up in the same
> 
> > field. And I need to split them into two fields. Note that if
> 
> > the text had said:
> 
> >
> 
> > "CAPSICUM RED fresh from QLD"
> 
> >
> 
> > I would want QLD in the description, not shunted forwards and
> 
> > put in the product name. So (uncontrived) list comprehensions
> 
> > and regex's are out.
> 
> >
> 
> > I want to split the above into:
> 
> >
> 
> > ("CAPSICUM RED", "fresh from QLD")
> 
> >
> 
> > Enter dropwhile and takewhile. 6 lines later:
> 
> >
> 
> > from itertools import takewhile, dropwhile
> 
> > def split_product_itertools(s):
> 
> > words = s.split()
> 
> > allcaps = lambda word: word == word.upper()
> 
> > product, description = takewhile(allcaps, words), dropwhile(allcaps, 
> > words)
> 
> > return " ".join(product), " ".join(description)
> 
> >
> 
> > When I tried to refactor this code to use while or for loops, I
> 
> > couldn't find any way that felt shorter or more pythonic:
> 
> 
> 
> I'm really tempted to import re, and that means takewhile and
> 
> dropwhile need to stay. ;)
> 
> 
> 
> But seriously, this is a quick implementation of my first thought.
> 
> 
> 
> description = s.lstrip(string.ascii_uppercase + ' ')
> 
> product = s[:-len(description)-1]
> 
> 
> 
> -- 
> 
> Neil Cerutti

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


Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Neil Cerutti
On 2012-12-04, Nick Mellor  wrote:
> Hi Neil,
>
> Nice! But fails if the first word of the description starts
> with a capital letter.

Darn edge cases.

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


Re: using smtp sent large file upto 60MB

2012-12-04 Thread moonhkt
On Dec 4, 6:07 pm, Chris Angelico  wrote:
> On Tue, Dec 4, 2012 at 7:15 PM, moonhkt  wrote:
> > How to using python send file uptp 60MB ?
>
> Step one: Don't. SMTP is almost never the best choice for sending huge
> files around.
>
> There are plenty of other ways to share files; send an email with
> instructions on how to access the file, rather than attaching the
> file. For general consumption, the easiest way is usually to include a
> URL for HTTP download. If it's something internal, you might want to
> put the file on a shared-access FTP server or file share.
>
> ChrisA

Thank for suggestion. The next task will be ftp to user folder. But
first tasks is how to using python send huge files.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New tutorials

2012-12-04 Thread Mitya Sirenef

On 12/02/2012 09:54 AM, Mitya Sirenef wrote:
Hi everyone, I'm making a series of python tutorials and I've just 
finished the introductory part: http://lightbird.net/larks/intro.html


Feedback is appreciated.. - mitya




I've just added a new section 'blocky blocks', which is a clone of 
'jumping blocks' game:


http://lightbird.net/larks/blockyblocks.html

I've used some rare unicode symbols in the game, they look a little 
strange in Gvim
but seem to work fine in my terminal and browser. If you experience 
issues, please

let me know. I've only tested in Linux terminal.

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


Re: using smtp sent large file upto 60MB

2012-12-04 Thread Laszlo Nagy



Thank for suggestion. The next task will be ftp to user folder. But
first tasks is how to using python send huge files.
Most SMTP servers are configured not to accept attachments bigger than 
10 or 15MB. In general, you should never send emails with >5MB 
attachments. Not because it is not possible, but because it is 
unreliable, and the solution is never in your hand. The solution depends 
on the SMTP server configuration, and in most cases you don't have 
access to the computers holding the final destination of the emails.


If you still don't want to accept this suggestion, then go ahead! Write 
a program, send out 100MB emails, and you will see for yourself that it 
just doesn't work.



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


Re: problem with usbtmc-communication

2012-12-04 Thread Jean Dubois
On 4 dec, 15:33, [email protected] wrote:
> On Dec 4, 2012, at 7:14 AM, Jean Dubois  wrote:
>
>
>
> > The following test program which tries to communicate with a Keithley
> > 2200 programmable power supply using usbtmc in Python does not work as
> > expected. I have connected a 10 ohm resistor to its terminals and I
> > apply 0.025A, 0.050A, 0.075A en 0.1A,
> > I then measure the current and the voltage en write them in a file
> > De data produced looks like this:
> > 0.00544643 0.254061; first current value is wrong, voltage value is
> > correct
> > 0.0250807 0.509289; second current value is wrong, but it corresponds
> > to the first, second voltage is correct
> > 0.0501099 0.763945; 3rd current value is wrong, but it corresponds to
> > the second, 3rd voltage is right
> > 0.075099 1.01792; 4th current value is wrong,  it corresponds to the
> > 3rd, 4th voltage is right
> >                            4th correct current value is missing
>
> > But is should be (numerical inaccuracy taking into account)(these data
> > were produced by a similar octave-program):
> > 0.0248947 0.254047
> > 0.0499105 0.509258
> > 0.0749044 0.764001
> > 0.0998926 1.01828
>
> > Here is the python-program:
> > #!/usr/bin/python
> > import time
> > import os
> > import sys
> > measurementcurr=''
> > measurementvolt=''
> > timesleepdefault=1
> > filename ='mydata.txt'
> > usbkeith = open('/dev/usbtmc1','r+')
> > usbkeith.flush()
> > usbkeith.write("*IDN?\n")
> > #strip blank line:
> > identification=usbkeith.readline().strip()
> > print 'Found device: ',identification
> > usbkeith.write("SYST:REM" + "\n")
> > usbkeith.write(":SENS:VOLT:PROT 1.5\n")
> > keithdata = open(filename,'w')
> > #start first measurement
> > usbkeith.write(":SOUR:CURR 0.025\n")
> > usbkeith.write(":OUTP:STAT ON\n")
> > time.sleep(timesleepdefault)
> > usbkeith.write(":MEAS:CURR?\n")
> > time.sleep(timesleepdefault)
> > measurementcurr=usbkeith.readline()
> > print 'Measured current 1: ',measurementcurr
> > usbkeith.write("MEAS:VOLT?\n")
> > time.sleep(timesleepdefault)
> > measurementvolt=usbkeith.readline()
> > print 'Measured voltage 1: ',measurementvolt
> > keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> > #start second measurement
> > usbkeith.write("SOUR:CURR 0.050\n")
> > time.sleep(timesleepdefault)
> > usbkeith.write("MEAS:CURR?\n")
> > time.sleep(timesleepdefault)
> > measurementcurr=usbkeith.readline()
> > print 'Measured current 2: ',measurementcurr
> > usbkeith.write("MEAS:VOLT?\n")
> > time.sleep(timesleepdefault)
> > measurementvolt=usbkeith.readline()
> > print 'Measured voltage 2: ',measurementvolt
> > keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> > #start 3rd measurement
> > time.sleep(timesleepdefault)
> > usbkeith.write("SOUR:CURR 0.075\n")
> > time.sleep(timesleepdefault)
> > usbkeith.write("MEAS:CURR?\n")
> > time.sleep(timesleepdefault)
> > measurementcurr=usbkeith.readline()
> > print 'Measured current 3: ',measurementcurr
> > usbkeith.write("MEAS:VOLT?\n")
> > time.sleep(timesleepdefault)
> > measurementvolt=usbkeith.readline()
> > print 'Measured voltage 3: ',measurementvolt
> > keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> > #start 4th measurement
> > time.sleep(timesleepdefault)
> > usbkeith.write("SOUR:CURR 0.1\n")
> > time.sleep(timesleepdefault)
> > usbkeith.write("MEAS:CURR?\n")
> > time.sleep(timesleepdefault)
> > measurementcurr=usbkeith.readline()
> > print 'Measured current 4: ',measurementcurr
> > usbkeith.write("MEAS:VOLT?\n")
> > time.sleep(timesleepdefault)
> > measurementvolt=usbkeith.readline()
> > print 'Measured voltage 4: ',measurementvolt
> > keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> > usbkeith.write(":OUTP:STAT OFF\n")
> > print "Goodbye, data logged in file:"
> > print filename
> > usbkeith.close()
> > keithdata.close()
>
> > can anyone here what is going wrong and how to get it right?
>
> > thanks
> > jean
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> Just guessing here - it looks as though you are setting the current and THEN 
> turning the output on.  That might be the correct sequence or it might not.
>  If not, it would explain the offset between that and the subsequent readings.
I changed the order of the two commands (first turn the source on then
set the current) and this is the result
0.0994434 0.253431; first current value wrong but the value seems what
the last one should be!, voltage correct
0.0251083 0.508319; second current value wrong but this is what the
first should be, voltage correct
0.0501242 0.762834; 3rd current value wrong but this is what the
second current value should ve, voltage correct
0.0749226 1.0167: 4th current value wrong but this is what the 3rd
current value should be, voltage correct

>
> This is really a Keithley problem, not a Python problem.
I thought also it was a Keithley problem but then I programmed exactly
the same in octave and with octave I do get the correct results, so I
think no

Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Alexander Blinne
Another neat solution with a little help from

http://stackoverflow.com/questions/1701211/python-return-the-index-of-the-first-element-of-a-list-which-makes-a-passed-fun

>>> def split_product(p):
... w = p.split(" ")
... j = (i for i,v in enumerate(w) if v.upper() != v).next()
... return " ".join(w[:j]), " ".join(w[j:])

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


Re: Working with classes

2012-12-04 Thread Jean-Michel Pichavant
- Original Message -
> Hello, I've been working on this program for a long time but can't
> seem to get it to work.. The first array is the input file, then a
> class, another class and the actual program. Could anyone see what
> is wrong? I'm sorry if the program doesn't make any sense at all
>  I'm just starting to learn this..
> 
> The exercise wants us to do the following:
> 5,4 4,5 8,7
> Add behind 6,3 3,2 9,6 4,3
> Add in front 7,6
> Add behind 9,8
> Add in front 5,5 7,8 6,5 6,4
> These are coordinates in the form(x,y) and the x coordinates need to
> be raised by 1.
> 
> pirateinvoer:
> 5,4 4,5 8,7=6,3 3,2 9,6 4,3=7,6=9,8=5,5 7,8 6,5 6,4
> 

Sorry I tried to guess what your trying to do for 10 minutes, but can't figure 
it out.
The code doesn't help either.

What is your input ? a file ? what is __exactly__ its content?
What is the output ? a file ? what's the content.

What is pirateinvoer ? an input, an output ?

What is the meaning of = in pirateinvoer ?

cheers,

JM

 


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


paramiko.BadAuthenticationType

2012-12-04 Thread Theta Sigma
Hi,

I'm trying to create a SSH connection with the paramiko module, and
I'm running to this error...

>> import os, paramiko
>> ssh = paramiko.SSHClient()
>> ssh.load_system_host_keys()
>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>> ssh.connect('...',username='...',password='...')
Traceback (most recent call last):
  File "", line 1 in 
  File "build\bdist.win-amd64\egg\paramiko\client,py", line 338, in
connect
  File "build\bdist.win-amd64\egg\paramiko\client.py", line 519, in
_auth
paramiko.BadAuthenticationType: Bad authentication type
(allowed_types=['publickey']
>> No handlers could be found for logger "paramiko.transport"


What am I doing wrong?

I'm running Python 2.7 on Windows 7, with paramiko-1.7.7.1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Neil Cerutti
On 2012-12-04, Nick Mellor  wrote:
> I love the way you guys can write a line of code that does the
> same as 20 of mine :)
>
> I can turn up the heat on your regex by feeding it a null
> description or multiple white space (both in the original
> file.) I'm sure you'd adjust, but at the cost of a more complex
> regex.

A re.split should be able to handle this without too much hassle.

The simplicity of my two-line version will evaporate pretty
quickly to compensate for edge cases.

Here's one that can handle one of the edge cases you mention, but
it's hardly any shorter than what you had, and it doesn't
preserve non-standard whites space, like double spaces.

def prod_desc(s):
"""split s into product name and product description. Product
name is a series of one or more capitalized words followed
by white space. Everything after the trailing white space is
the product description.

>>> prod_desc("CAR FIFTY TWO Chrysler LeBaron.")
['CAR FIFTY TWO', 'Chrysler LeBaron.']
"""
prod = []
desc = []
target = prod
for word in s.split():
if target is prod and not word.isupper():
target = desc
target.append(word)
return [' '.join(prod), ' '.join(desc)]

When str methods fail I'll usually write my own parser before
turning to re. The following is no longer nice looking at all.

def prod_desc(s):
"""split s into product name and product description. Product
name is a series of one or more capitalized words followed
by white space. Everything after the trailing white space is
the product description.

>>> prod_desc("CAR FIFTY TWO Chrysler LeBaron.")
['CAR FIFTY TWO', 'Chrysler LeBaron.']

>>> prod_desc("MR.  JONESEY   Saskatchewan's finest")
['MR.  JONESEY', "Saskatchewan's finest"]
"""
i = 0
while not s[i].islower():
i += 1
i -= 1
while not s[i].isspace():
i -= 1
start_desc = i+1
while s[i].isspace():
i -= 1
end_prod = i+1
return [s[:end_prod], s[start_desc:]]

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


Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread DJC

On 04/12/12 17:18, Alexander Blinne wrote:

Another neat solution with a little help from

http://stackoverflow.com/questions/1701211/python-return-the-index-of-the-first-element-of-a-list-which-makes-a-passed-fun


def split_product(p):

 w = p.split(" ")
 j = (i for i,v in enumerate(w) if v.upper() != v).next()
 return " ".join(w[:j]), " ".join(w[j:])


Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> w1 = "CAPSICUM RED Fresh from Queensland"
>>> w1.split()
['CAPSICUM', 'RED', 'Fresh', 'from', 'Queensland']
>>> w = w1.split()

>>> (i for i,v in enumerate(w) if v.upper() != v)
 at 0x18b1910>
>>> (i for i,v in enumerate(w) if v.upper() != v).next()
2

Python 3.2.3 (default, Oct 19 2012, 19:53:16)

>>> (i for i,v in enumerate(w) if v.upper() != v).next()
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'generator' object has no attribute 'next'

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


Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Alexander Blinne
Am 04.12.2012 19:28, schrieb DJC:
 (i for i,v in enumerate(w) if v.upper() != v).next()
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'generator' object has no attribute 'next'

Yeah, i saw this problem right after i sent the posting. It now is
supposed to read like this

>>> def split_product(p):
... w = p.split(" ")
... j = next(i for i,v in enumerate(w) if v.upper() != v)
... return " ".join(w[:j]), " ".join(w[j:])

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


Python Cluster

2012-12-04 Thread subhabangalore
Dear Group,

I am trying to use the cluster module as,
>>> from cluster import *
>>> data = [12,34,23,32,46,96,13]
>>> cl = HierarchicalClustering(data, lambda x,y: abs(x-y))
>>> cl.getlevel(10)
[[96], [46], [12, 13, 23, 34, 32]]
>>> cl.getlevel(5)
[[96], [46], [12, 13], [23], [34, 32]]

but now I want to visualize it if any one suggest how may I use 
visualization(like matplotlib or pyplot etc.) to see the data?

Thanking in advance,
Regards,
Subhabrata.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Cluster

2012-12-04 Thread Dave Angel
On 12/04/2012 02:04 PM, [email protected] wrote:
> Dear Group,
>
> I am trying to use the cluster module as,
 from cluster import *

No such module in the stdlib.

Start by showing what OS, what Python version, and what external
libraries you've installed and are using, and only then can you ask a
meaningful question.



-- 

DaveA

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


Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Ian Kelly
On Tue, Dec 4, 2012 at 11:48 AM, Alexander Blinne  wrote:

> Am 04.12.2012 19:28, schrieb DJC:
>  (i for i,v in enumerate(w) if v.upper() != v).next()
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > AttributeError: 'generator' object has no attribute 'next'
>
> Yeah, i saw this problem right after i sent the posting. It now is
> supposed to read like this
>
> >>> def split_product(p):
> ... w = p.split(" ")
> ... j = next(i for i,v in enumerate(w) if v.upper() != v)
> ... return " ".join(w[:j]), " ".join(w[j:])
>

It still fails if the product description is empty.

>>> split_product("CAPSICUM RED")
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 3, in split_product
StopIteration

I'm not meaning to pick on you; some of the other solutions in this thread
also fail in that case.

>>> re.findall(r"(?m)^([A-Z\s]+) (.+)$", "CAPSICUM RED")
[('CAPSICUM', 'RED')]

>>> prod_desc("CAPSICUM RED")  # the second version from Neil's post
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 14, in prod_desc
IndexError: string index out of range
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] problem with usbtmc-communication

2012-12-04 Thread Terry Reedy

On 12/4/2012 7:14 AM, Jean Dubois wrote:

The following test program which tries to communicate with a Keithley
2200 programmable power supply using usbtmc in Python does not work as
expected. I have connected a 10 ohm resistor to its terminals and I
apply 0.025A, 0.050A, 0.075A en 0.1A,
I then measure the current and the voltage en write them in a file
De data produced looks like this:
0.00544643 0.254061; first current value is wrong, voltage value is
correct
0.0250807 0.509289; second current value is wrong, but it corresponds
to the first, second voltage is correct
0.0501099 0.763945; 3rd current value is wrong, but it corresponds to
the second, 3rd voltage is right
0.075099 1.01792; 4th current value is wrong,  it corresponds to the
3rd, 4th voltage is right
 4th correct current value is missing

But is should be (numerical inaccuracy taking into account)  (these data
were produced by a similar octave-program):
0.0248947 0.254047
0.0499105 0.509258
0.0749044 0.764001
0.0998926 1.01828

Here is the python-program:
#!/usr/bin/python
import time
import os
import sys



measurementcurr=''
measurementvolt=''
timesleepdefault=1
filename ='mydata.txt'
usbkeith = open('/dev/usbtmc1','r+')
usbkeith.flush()
usbkeith.write("*IDN?\n")
#strip blank line:
identification=usbkeith.readline().strip()
print 'Found device: ',identification
usbkeith.write("SYST:REM" + "\n")
usbkeith.write(":SENS:VOLT:PROT 1.5\n")
keithdata = open(filename,'w')



#start first measurement
usbkeith.write(":SOUR:CURR 0.025\n")
usbkeith.write(":OUTP:STAT ON\n")
time.sleep(timesleepdefault)
usbkeith.write(":MEAS:CURR?\n")
time.sleep(timesleepdefault)
measurementcurr=usbkeith.readline()
print 'Measured current 1: ',measurementcurr
usbkeith.write("MEAS:VOLT?\n")
time.sleep(timesleepdefault)
measurementvolt=usbkeith.readline()
print 'Measured voltage 1: ',measurementvolt
keithdata.write(measurementcurr.strip()+' '+measurementvolt)

[3 near repetitions snipped]

This sort of repetitious code without even line breaks is painful for me 
to read. Python has looping statements for a reason. Replace all four 
nearly identical blocks with the following. (If you are not familiar 
with built-in enumerate, you should be. Read its entry in the library 
manual.)


for number, current_in in enumerate(
('0.025', '0.050'. '0.075', '0.100'), 1)
  usbkeith.write(":SOUR:CURR %s\n" % current_in)
  ...
  print 'Measured current %d: ' % number, measurementcurr
  ...
  print 'Measured voltage %d: ' % number, measurementvolt

Now you can make changes in only one place and easily add more test values.


print "Goodbye, data logged in file:"
print filename
usbkeith.close()
keithdata.close()

can anyone here what is going wrong and how to get it right?


No, but if both the python and octave programs used loops, it would be 
easier to see if both are doing the same things before, within, and 
after the loop.


--
Terry Jan Reedy

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


The Select Group- Raleigh, NC

2012-12-04 Thread Whitney Holman
PYTHON DEVELOPER NEEDED - EXCITING OPPORTUNITY IN MORRISVILLE, NC
The Select Group is seeking a Python software engineer for fun, energetic, and 
growing company in Morrisville, NC.  The ideal candidate will have hands-on 
development experience, and must have working knowledge of Python.  A very 
casual, but fast-paced environment, the company promotes internal growth for 
people with a willingness to learn and a passion for software development.
 RESPONSIBILITIES

  *   New Product Development, and Existing Product Support
  *   In Charge of Multiple Internal & External Websites
REQUIREMENTS

  *   1-3 years of development experience
  *   Python experience

PLUSES

  *   Experience with C++, Java, or Perl
  *   Hands on work with SQL, PHP, and Linux
  *   Previously worked with a Content Management System:  WordPress, Joomla, 
or Drupal


Whitney Holman
Technical Recruiter
THE SELECT GROUP

Direct: 919.459.1040 |  Cell: 704.264.6273
[email protected]|  
LinkedIn
5420 Wade Park Blvd. Ste 100  |  Raleigh, NC 27607




Web Site| Corporate 
Video | 
Awards | Career 
Resources

At The Select Group we're dedicated to delivering the best experience for our 
candidates and clients.
We appreciate any and all feedback. Please contact my manager, Byron Dunn at 
[email protected].

"Connecting great companies with quality talent."...see how at The Select Group 
Advantage

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


Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread MRAB

On 2012-12-04 19:37, Ian Kelly wrote:

On Tue, Dec 4, 2012 at 11:48 AM, Alexander Blinne mailto:[email protected]>> wrote:

Am 04.12.2012 19:28, schrieb DJC:
  (i for i,v in enumerate(w) if v.upper() != v).next()
 > Traceback (most recent call last):
 >   File "", line 1, in 
 > AttributeError: 'generator' object has no attribute 'next'

Yeah, i saw this problem right after i sent the posting. It now is
supposed to read like this

 >>> def split_product(p):
... w = p.split(" ")
... j = next(i for i,v in enumerate(w) if v.upper() != v)
... return " ".join(w[:j]), " ".join(w[j:])


It still fails if the product description is empty.

 >>> split_product("CAPSICUM RED")
Traceback (most recent call last):
   File "", line 1, in 
   File "", line 3, in split_product
StopIteration

I'm not meaning to pick on you; some of the other solutions in this
thread also fail in that case.

 >>> re.findall(r"(?m)^([A-Z\s]+) (.+)$", "CAPSICUM RED")
[('CAPSICUM', 'RED')]


That's easily fixed:

>>> re.findall(r"(?m)^([A-Z\s]+)(?: (.*))?$", "CAPSICUM RED")
[('CAPSICUM RED', '')]


 >>> prod_desc("CAPSICUM RED")  # the second version from Neil's post
Traceback (most recent call last):
   File "", line 1, in 
   File "", line 14, in prod_desc
IndexError: string index out of range



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


Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Alexander Blinne
Am 04.12.2012 20:37, schrieb Ian Kelly:
> >>> def split_product(p):
> ... w = p.split(" ")
> ... j = next(i for i,v in enumerate(w) if v.upper() != v)
> ... return " ".join(w[:j]), " ".join(w[j:])
> 
> 
> It still fails if the product description is empty.

That's true... let's see, next() takes a default value in case the
iterator is empty and then we could use some special value and test for
it. But i think it would be more elegant to just handle the excepten
ourselves, so:

>>> def split_product(p):
... w = p.split(" ")
... try:
... j = next(i for i,v in enumerate(w) if v.upper() != v)
... except StopIteration:
... return p, ''
... return " ".join(w[:j]), " ".join(w[j:])

> I'm not meaning to pick on you; some of the other solutions in this
> thread also fail in that case.

It's ok, opening the eye for edge cases is always a good idea :)

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


Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Terry Reedy

On 12/4/2012 8:57 AM, Nick Mellor wrote:


I have a file full of things like this:

"CAPSICUM RED fresh from Queensland"

Product names (all caps, at start of string) and descriptions (mixed
case, to end of string) all muddled up in the same field. And I need
to split them into two fields. Note that if the text had said:

"CAPSICUM RED fresh from QLD"

I would want QLD in the description, not shunted forwards and put in
the product name. So (uncontrived) list comprehensions and regex's
are out.

I want to split the above into:

("CAPSICUM RED", "fresh from QLD")

Enter dropwhile and takewhile. 6 lines later:

from itertools import takewhile, dropwhile
def split_product_itertools(s):

>   words = s.split()
>   allcaps = lambda word: word == word.upper()
>   product, description =\
>   takewhile(allcaps, words), dropwhile(allcaps, words)
>   return " ".join(product), " ".join(description)

If the original string has no excess whitespace, description is what 
remains of s after product prefix is omitted. (Py 3 code)


from itertools import takewhile
def allcaps(word): return word == word.upper()

def split_product_itertools(s):
product = ' '.join(takewhile(allcaps, s.split()))
return product, s[len(product)+1:]

print(split_product_itertools("CAPSICUM RED fresh from QLD"))
>>>
('CAPSICUM RED', 'fresh from QLD')

Without that assumption, the same idea applies to the split list.

def split_product_itertools(s):
words = s.split()
product = list(takewhile(allcaps, words))
return ' '.join(product), ' '.join(words[len(product):])

--
Terry Jan Reedy

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


Re: using smtp sent large file upto 60MB

2012-12-04 Thread Chris Angelico
On Wed, Dec 5, 2012 at 2:41 AM, Laszlo Nagy  wrote:
> If you still don't want to accept this suggestion, then go ahead! Write a
> program, send out 100MB emails, and you will see for yourself that it just
> doesn't work.

But be aware of a few things.

1) Converting 1MB of binary data into a MIME-packaged email is going
to result in about 2MB of text. (It's about 1.5MB for base 64
encoding, which is one of the most common used, plus a bit more for
structure around it, and rounding up, call it two meg.)

2) If that 2MB of text is stored as a Python text string, it could
potentially consume 4MB or 8MB of memory, unless you're on Python 3.3,
in which case it will be only 2MB..

3) That 2-8MB has to be contiguous.

4) Any manipulation of the resulting string - which will quite
probably happen as it's built, as it gets connected to the email, etc,
etc, etc - will require even more copies of the string.

So all in all, you need a LOT of memory to do your encoding. That's
why you're seeing MemoryError - it is simply impossible to attach a
huge file to an email without using a fair amount of memory. (It's
possible to use that memory a bit at a time, but since emails are
generally small, most encoding libraries won't be written to do that.
This isn't like movie editing, where it's common to work with files
larger than your RAM.)

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


Re: Python Cluster

2012-12-04 Thread Ian Kelly
On Tue, Dec 4, 2012 at 12:04 PM,  wrote:

> Dear Group,
>
> I am trying to use the cluster module as,
> >>> from cluster import *
> >>> data = [12,34,23,32,46,96,13]
> >>> cl = HierarchicalClustering(data, lambda x,y: abs(x-y))
> >>> cl.getlevel(10)
> [[96], [46], [12, 13, 23, 34, 32]]
> >>> cl.getlevel(5)
> [[96], [46], [12, 13], [23], [34, 32]]
>
> but now I want to visualize it if any one suggest how may I use
> visualization(like matplotlib or pyplot etc.) to see the data?
>

You mean like a dendrogram?  Scipy has support for that.  It uses
matplotlib to do the actual plotting.

http://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.dendrogram.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Cluster

2012-12-04 Thread Miki Tebeka
On Tuesday, December 4, 2012 11:04:15 AM UTC-8, [email protected] wrote:
> >>> cl = HierarchicalClustering(data, lambda x,y: abs(x-y))
> but now I want to visualize it if any one suggest how may I use 
> visualization(like matplotlib or pyplot etc.) to see the data?
One option is to use a scatter plot with different color per cluster. See the 
many examples in http://matplotlib.org/gallery.html.

HTH,
--
Miki
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Vlastimil Brom
2012/12/4 Nick Mellor :
> I love the way you guys can write a line of code that does the same as 20 of 
> mine :)
> I can turn up the heat on your regex by feeding it a null description or 
> multiple white space (both in the original file.) I'm sure you'd adjust, but 
> at the cost of a more complex regex.
> Meanwhile takewith and dropwith are behaving themselves impeccably but my 
> while loop has fallen over.
>
> Best,
> Nick
>> [...]
> --

Hi,
well, for what is it worth, both cases could be addressed quite
easily, with little added complexity - e.g.: make the description part
optional, allow multiple whitespace and enforce word boundary after
the product name in order to get rid of the trailing whitespace in it:

>>> re.findall(r"(?m)^([A-Z\s]+\b)(?:\s+(.*))?$", "CAPSICUM RED fresh from 
>>> QLD\nCAPSICUMRED   fresh fromQueensland\nCAPSICUM RED")
[('CAPSICUM RED', 'fresh from QLD'), ('CAPSICUMRED', 'fresh from
 Queensland'), ('CAPSICUM RED', '')]
>>>

However, it's certainly preferable to use a solution you are more
comfortable with, e.g. the itertools one...

regards,
   vbr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Steven D'Aprano
Ian,

For the sanity of those of us reading this via Usenet using the Pan 
newsreader, could you please turn off HTML emailing? It's very 
distracting.

Thanks,

Steven


On Tue, 04 Dec 2012 12:37:38 -0700, Ian Kelly wrote:

[...]
> On Tue,
> Dec 4, 2012 at 11:48 AM, Alexander Blinne < href="mailto:[email protected]";
> target="_blank">[email protected]> wrote: class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc
> solid;padding-left:1ex">
> 
> Am 04.12.2012 19:28, schrieb DJC: 
> (i for i,v in enumerate(w) if v.upper() != v).next() > Traceback
> (most recent call last): >   File "", line
> 1, in  > AttributeError: 'generator' object
> has no attribute 'next' 
> Yeah, i saw this problem right after i sent the posting. It now
> is supposed to read like this
> 
> >>> def split_product(p): ...     w = p.split("
> ") ...     j = next(i for i,v in enumerate(w) if
> v.upper() != v) ...     return "
> ".join(w[:j]), "
> ".join(w[j:])It still fails if the
> product description is empty.>>>
> split_product("CAPSICUM RED")
> 
> Traceback (most recent call last):  File "",
> line 1, in   File "", line 3,
> in split_productStopIterationI'm not meaning to pick on
> you; some of the other solutions in this thread also fail in that
> case.
> 
> >>> re.findall(r"(?m)^([A-Z\s]+) (.+)$",
> "CAPSICUM RED")[('CAPSICUM',
> 'RED')]>>> prod_desc("CAPSICUM RED") 
> # the second version from Neil's post
> 
> Traceback (most recent call last):  File "",
> line 1, in   File "", line 14,
> in prod_descIndexError: string index out of range


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


assign only first few items of a tuple/list

2012-12-04 Thread Daniel Fetchinson
Hi folks, I swear I used to know this but can't find it anywhere.
Say I have a list x = [ 1,2,3,4,5 ] and only care about the first two items.
I'd like to assign the first two items to two variables, something like,

a, b, _ = x

but the above will not work, of course, but what is the common idiom
for this that does?

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assign only first few items of a tuple/list

2012-12-04 Thread Chris Angelico
On Wed, Dec 5, 2012 at 8:25 AM, Daniel Fetchinson
 wrote:
> Hi folks, I swear I used to know this but can't find it anywhere.
> Say I have a list x = [ 1,2,3,4,5 ] and only care about the first two items.
> I'd like to assign the first two items to two variables, something like,
>
> a, b, _ = x
>
> but the above will not work, of course, but what is the common idiom
> for this that does?

Try this:

a, b, *_ = x

Assigns 1 to a, 2 to b, and [3,4,5] to _

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


Re: assign only first few items of a tuple/list

2012-12-04 Thread Terry Reedy

On 12/4/2012 4:36 PM, Chris Angelico wrote:

On Wed, Dec 5, 2012 at 8:25 AM, Daniel Fetchinson
 wrote:

Hi folks, I swear I used to know this but can't find it anywhere.
Say I have a list x = [ 1,2,3,4,5 ] and only care about the first two items.
I'd like to assign the first two items to two variables, something like,

a, b, _ = x

but the above will not work, of course, but what is the common idiom
for this that does?


Try this:

a, b, *_ = x

Assigns 1 to a, 2 to b, and [3,4,5] to _


Or a, b = x[0:2]; depending on whether you do or do not want the 
remainder as a separate item.


--
Terry Jan Reedy

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


Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Terry Reedy

On 12/4/2012 3:44 PM, Terry Reedy wrote:


If the original string has no excess whitespace, description is what
remains of s after product prefix is omitted. (Py 3 code)

from itertools import takewhile
def allcaps(word): return word == word.upper()

def split_product_itertools(s):
 product = ' '.join(takewhile(allcaps, s.split()))
 return product, s[len(product)+1:]

print(split_product_itertools("CAPSICUM RED fresh from QLD"))
 >>>
('CAPSICUM RED', 'fresh from QLD')

Without that assumption, the same idea applies to the split list.

def split_product_itertools(s):
 words = s.split()
 product = list(takewhile(allcaps, words))
 return ' '.join(product), ' '.join(words[len(product):])


Because these slice rather than index, either works trivially on an 
empty description.


print(split_product_itertools("CAPSICUM RED"))
>>>
('CAPSICUM RED', '')



--
Terry Jan Reedy

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


Re: assign only first few items of a tuple/list

2012-12-04 Thread Dave Angel
On 12/04/2012 04:36 PM, Chris Angelico wrote:
> On Wed, Dec 5, 2012 at 8:25 AM, Daniel Fetchinson
>  wrote:
>> Hi folks, I swear I used to know this but can't find it anywhere.
>> Say I have a list x = [ 1,2,3,4,5 ] and only care about the first two items.
>> I'd like to assign the first two items to two variables, something like,
>>
>> a, b, _ = x
>>
>> but the above will not work, of course, but what is the common idiom
>> for this that does?
> Try this:
>
> a, b, *_ = x
>
> Assigns 1 to a, 2 to b, and [3,4,5] to _
>
If you're on Python 3.x.  If you're on 2.x, you need to do a slice
notation like Terry points out.


-- 

DaveA

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


Re: assign only first few items of a tuple/list

2012-12-04 Thread Tim Chase
On 12/04/12 15:36, Chris Angelico wrote:
> On Wed, Dec 5, 2012 at 8:25 AM, Daniel Fetchinson
>  wrote:
>> Hi folks, I swear I used to know this but can't find it anywhere.
>> Say I have a list x = [ 1,2,3,4,5 ] and only care about the first two items.
>> I'd like to assign the first two items to two variables, something like,
>>
>> a, b, _ = x
>>
>> but the above will not work, of course, but what is the common idiom
>> for this that does?
> 
> Try this:
> 
> a, b, *_ = x
> 
> Assigns 1 to a, 2 to b, and [3,4,5] to _

Just to complete the picture, that's a Py3k thing.  And it only
works with finite iterables (such as lists).  In 2.x, you have to
use Terry Reedy's slicing suggestion.

-tkc



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


Re: using smtp sent large file upto 60MB

2012-12-04 Thread moonhkt
On 12月5日, 上午4時54分, Chris Angelico  wrote:
> On Wed, Dec 5, 2012 at 2:41 AM, Laszlo Nagy  wrote:
> > If you still don't want to accept this suggestion, then go ahead! Write a
> > program, send out 100MB emails, and you will see for yourself that it just
> > doesn't work.
>
> But be aware of a few things.
>
> 1) Converting 1MB of binary data into a MIME-packaged email is going
> to result in about 2MB of text. (It's about 1.5MB for base 64
> encoding, which is one of the most common used, plus a bit more for
> structure around it, and rounding up, call it two meg.)
>
> 2) If that 2MB of text is stored as a Python text string, it could
> potentially consume 4MB or 8MB of memory, unless you're on Python 3.3,
> in which case it will be only 2MB..
>
> 3) That 2-8MB has to be contiguous.
>
> 4) Any manipulation of the resulting string - which will quite
> probably happen as it's built, as it gets connected to the email, etc,
> etc, etc - will require even more copies of the string.
>
> So all in all, you need a LOT of memory to do your encoding. That's
> why you're seeing MemoryError - it is simply impossible to attach a
> huge file to an email without using a fair amount of memory. (It's
> possible to use that memory a bit at a time, but since emails are
> generally small, most encoding libraries won't be written to do that.
> This isn't like movie editing, where it's common to work with files
> larger than your RAM.)
>
> ChrisA

Thank for your suggestion.

Machine : AIX
Python version : 2.6.2

I am prepare change UNIX script to Python. smtp and ftp are my first
tasks.

But, when using standard unix command mail and uuencode without this
issue.

Our SMTP can send file more than 60MB. But our notes server can
configured 100MB,30MB or 10MB. My notes Mail box can receive 100MB.

In UNIX, by below command send  smtp mail.
uuencode $xfn $xfn | mail -s "$SUBJECT" $NAME

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


Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread Nick Mellor
Hi Terry,

For my money, and especially in your versions, despite several expert solutions 
using other features, itertools has it. It seems to me to need less nutting out 
than the other approaches. It's short, robust, has a minimum of symbols, uses 
simple expressions and is not overly clever. If we could just get used to using 
takewhile.

takewhile mines for gold at the start of a sequence, dropwhile drops the dross 
at the start of a sequence.

Thanks all for your interest and your help,

Best,

Nick

Terry's implementations:

> from itertools import takewhile
> 
> def allcaps(word): return word == word.upper()
> 
> 
> 
> def split_product_itertools(s):
> 
>  product = ' '.join(takewhile(allcaps, s.split()))
> 
>  return product, s[len(product)+1:]
> 
> 
> 
> print(split_product_itertools("CAPSICUM RED fresh from QLD"))
> 
>  >>>
> 
> ('CAPSICUM RED', 'fresh from QLD')
> 
> 
> 
> [if there could be surplus whitespace], the same idea applies to the split 
> list.
> 
> 
> 
> def split_product_itertools(s):
> 
>  words = s.split()
> 
>  product = list(takewhile(allcaps, words))
> 
>  return ' '.join(product), ' '.join(words[len(product):])
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


How to determine if printing is being a bottleneck in my code?

2012-12-04 Thread SherjilOzair
Hello list,

When it comes to printing things while some computation is being done, there 
are 2 extremes.

1. printing speed is slower than data-to-print generation speed. In this case, 
printing is a bottleneck. Examples: "for i in xrange(2**30): print i". Without 
the print, this code would be much faster.

2. data-to-print generation speed is slower than printing speed. So, this case, 
printing does now slow you down much. Example: for m in matrices: print 
m.inverse() # inverse is a time-taking function

These two cases are pretty easy. But, my question is, how to draw the line? How 
do I know that print is slowing me down, and I should probably remove some of 
them? Is there a scientific way to do this, rather than just intuition and 
guesswork?

I can clarify, if needed.
Thanks,
Sherjil Ozair
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Cluster

2012-12-04 Thread subhabangalore
On Wednesday, December 5, 2012 2:33:56 AM UTC+5:30, Miki Tebeka wrote:
> On Tuesday, December 4, 2012 11:04:15 AM UTC-8, [email protected] wrote:
> 
> > >>> cl = HierarchicalClustering(data, lambda x,y: abs(x-y))
> 
> > but now I want to visualize it if any one suggest how may I use 
> > visualization(like matplotlib or pyplot etc.) to see the data?
> 
> One option is to use a scatter plot with different color per cluster. See the 
> many examples in http://matplotlib.org/gallery.html.
> 
> 
> 
> HTH,
> 
> --
> 
> Miki

Thanks Miki. Good Gallery I think it'd do. We can plot as we feel. 
Regards,Subhabrata.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to determine if printing is being a bottleneck in my code?

2012-12-04 Thread Roy Smith
In article <[email protected]>,
 SherjilOzair  wrote:

> Hello list,
> 
> When it comes to printing things while some computation is being done, there 
> are 2 extremes.
> 
> 1. printing speed is slower than data-to-print generation speed. In this 
> case, printing is a bottleneck. Examples: "for i in xrange(2**30): print i". 
> Without the print, this code would be much faster.
> 
> 2. data-to-print generation speed is slower than printing speed. So, this 
> case, printing does now slow you down much. Example: for m in matrices: print 
> m.inverse() # inverse is a time-taking function
> 
> These two cases are pretty easy. But, my question is, how to draw the line? 
> How do I know that print is slowing me down, and I should probably remove 
> some of them? Is there a scientific way to do this, rather than just 
> intuition and guesswork?
> 
> I can clarify, if needed.
> Thanks,
> Sherjil Ozair

The profiler (http://docs.python.org/2/library/profile.html) is your 
friend.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to determine if printing is being a bottleneck in my code?

2012-12-04 Thread rusi
On Dec 5, 7:36 am, Roy Smith  wrote:
> In article <[email protected]>,
>
>
>
>
>
>
>
>
>
>  SherjilOzair  wrote:
> > Hello list,
>
> > When it comes to printing things while some computation is being done, there
> > are 2 extremes.
>
> > 1. printing speed is slower than data-to-print generation speed. In this
> > case, printing is a bottleneck. Examples: "for i in xrange(2**30): print i".
> > Without the print, this code would be much faster.
>
> > 2. data-to-print generation speed is slower than printing speed. So, this
> > case, printing does now slow you down much. Example: for m in matrices: 
> > print
> > m.inverse() # inverse is a time-taking function
>
> > These two cases are pretty easy. But, my question is, how to draw the line?
> > How do I know that print is slowing me down, and I should probably remove
> > some of them? Is there a scientific way to do this, rather than just
> > intuition and guesswork?
>
> > I can clarify, if needed.
> > Thanks,
> > Sherjil Ozair
>
> The profiler (http://docs.python.org/2/library/profile.html) is your
> friend.

One added caveat: When 'printing' is the bottleneck it can be
- in the actual disk/console/network I/O
- in the str/repr builtin/customized that precedes it

[Or both of course]

So after you identify printing as the bottleneck, it may be worthwhile
to print to a dummy device.
On Unix one usually uses /dev/null for this but whether that will help
clarify or muddy the picture I am not sure (Whats the overhead to
writing to null?)
A more internal-to-python method may be to replace the print with a
str/repr assigned to say a global variable
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using smtp sent large file upto 60MB

2012-12-04 Thread Chris Angelico
On Wed, Dec 5, 2012 at 11:54 AM, moonhkt  wrote:
> I am prepare change UNIX script to Python. smtp and ftp are my first
> tasks.
>
> But, when using standard unix command mail and uuencode without this
> issue.
>
> Our SMTP can send file more than 60MB. But our notes server can
> configured 100MB,30MB or 10MB. My notes Mail box can receive 100MB.
>
> In UNIX, by below command send  smtp mail.
> uuencode $xfn $xfn | mail -s "$SUBJECT" $NAME

Yes, and it is possible to send that much content via SMTP. It just
isn't something that library authors are going to be overly concerned
about. You may need to jump through a few extra hoops, or maybe just
throw more RAM at the computer (possibly switching to a 64-bit build
of Python if you aren't already using one). However, I would *still*
recommend using a different transport for such large files.

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


How to check if Pexpect child already exist?

2012-12-04 Thread Thomas Elsgaard
Hi List

I am wondering, how can i check if child already exist before i spawn
? child.isalive() cannot be done on child before it has been spawned.

---
import pexpect

child=pexpect.spawn('ssh [email protected]')
child.sendline('test')
---

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


Re: using smtp sent large file upto 60MB

2012-12-04 Thread moonhkt
On 12月5日, 下午1時34分, Chris Angelico  wrote:
> On Wed, Dec 5, 2012 at 11:54 AM, moonhkt  wrote:
> > I am prepare change UNIX script to Python. smtp and ftp are my first
> > tasks.
>
> > But, when using standard unix command mail and uuencode without this
> > issue.
>
> > Our SMTP can send file more than 60MB. But our notes server can
> > configured 100MB,30MB or 10MB. My notes Mail box can receive 100MB.
>
> > In UNIX, by below command send  smtp mail.
> > uuencode $xfn $xfn | mail -s "$SUBJECT" $NAME
>
> Yes, and it is possible to send that much content via SMTP. It just
> isn't something that library authors are going to be overly concerned
> about. You may need to jump through a few extra hoops, or maybe just
> throw more RAM at the computer (possibly switching to a 64-bit build
> of Python if you aren't already using one). However, I would *still*
> recommend using a different transport for such large files.
>
> ChrisA

Thank a lot. We still using Python version : 2.6.2  on AIX 5.3

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