MySQLdb Help

2013-09-17 Thread Venkat Addala
Hi all,


  I'm new to python, i am connecting mysql database with python. now i want
to do sanitation on the database, like to remove "\n", extra spaces blah
blah.. and update it back to mysql database. i was trying somthing, here is
my code, can you please provide me solution for this..

#!/usr/bin/python
import MySQLdb as mdb

con = mdb.connect('localhost', 'root', 'pass@123', 'workbench');

with con:
  cur = con.cursor()
  cur.execute("SELECT descrip FROM table LIMIT 1")
  rows = cur.fetchall()
  for row in rows:
row_new = row[0].split("\n", " ")
row = "".join(row_new)
  print row
exit(0)
--

Regards
Boffin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb Help

2013-09-17 Thread Ben Finney
Venkat Addala  writes:

>   I'm new to python

Welcome! Congratulations on choosing Python for programming.

> i am connecting mysql database with python. now i want to do
> sanitation on the database, like to remove "\n", extra spaces blah
> blah.. and update it back to mysql database.


> i was trying somthing, here is my code, can you please provide me
> solution for this..

Thank you for providing a small, complete example.

You should also describe what behaviour you expect, and what behaviour
you're getting instead. What happens, and how are you expecting it to be
different?

> #!/usr/bin/python
> import MySQLdb as mdb
>
> con = mdb.connect('localhost', 'root', 'pass@123', 'workbench');

There's no need to end Python statements with a semicolon; it's only
confusing to do it.

>   rows = cur.fetchall()
>   for row in rows:

You never use ‘rows’ for anything else, so you may as well forget it and
just iterate directly over the return value::

for row in cur.fetchall():

> row_new = row[0].split("\n", " ")

Read the documentation for ‘str.split’ to see what is wrong with the
above call.


You might also be interested in the ‘python-tutor’ forum, specially
designed for beginners with basic questions about Python
http://mail.python.org/mailman/listinfo/tutor>
http://dir.gmane.org/gmane.comp.python.tutor>.

Good hunting to you!

-- 
 \ “Sunday: A day given over by Americans to wishing that they |
  `\  themselves were dead and in Heaven, and that their neighbors |
_o__)were dead and in Hell.” —Henry L. Mencken |
Ben Finney

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


Re: Qt connect and first connect or unicode

2013-09-17 Thread Oscar Benjamin
On 17 September 2013 05:12, Mohsen Pahlevanzadeh
 wrote:
> Dear all,
>
> Unfortunately, i confused and need help... the following code is:
> ###
> ##CheckBox:
> QtCore.QObject.connect(self.checkBox,
> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
> self.materialsInstance.setFilterDict("C",self,"name",self.lineEdit.text()))
>
> QtCore.QObject.connect(self.checkBox_2,
> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
> self.materialsInstance.setFilterDict("C",self,"bought_price",persianToInteger(unicode(self.lineEdit_2.text()
>
> QtCore.QObject.connect(self.checkBox_4,
> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
> self.materialsInstance.setFilterDict("C",self,"stock",persianToInteger(unicode(self.lineEdit_3.text()
>
> ##LineEdit
> QtCore.QObject.connect(self.lineEdit,
> QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda:
> self.materialsInstance.setFilterDict("L",self,"name",self.lineEdit.text()))
>
> QtCore.QObject.connect(self.lineEdit_2,
> QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda:
> self.materialsInstance.setFilterDict("L",self,"bought_price",persianToInteger(unicode(self.lineEdit_2.text()

I don't really know what the problem you're having is but this code is
very difficult to read.

What's the point of the _fromUTF8 function? The strings you pass it
are all ASCII, so if you're trying to create unicode strings you could
just use the u prefix e.g. u"toggled(bool)".

Also you can avoid referring to the same deeply nested attributes by
importing them or assigning them to something first e.g.:

from QtCore import SIGNAL
from QtCore.QObject import connect  # Not sure if QObject is a module...


## Checkbox:
setfilter = self.materialsInstance.setFilterDict

connect(self.checkBox, SIGNAL(u"toggled(bool)"),
lambda: setfilter("C", self, "name", self.lineEdit.text()))


Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb Help

2013-09-17 Thread Venkat Addala
hey Ben,

Thanks for your solution, i am done with this before, now i'm having
problem after deleting \n and extra spaces, i want to update it back it
again to mysql db.

For this i tried using regular expression  check this code;

# -*- coding: utf-8 -*-
import re
import MySQLdb

pattern = re.compile('@(.*)@.*$')

conn = MySQLdb.connect(
  host='localhost', user='root',
  passwd='pass123', db='workbench', charset='utf8')

cursor = conn.cursor()

cursor.execute("""
SELECT * FROM gene where gene_id=13 AND `descrip` regexp "^@.*@.*$"
LIMIT 1""")
rows = cursor.fetchall()
for row in rows:
  rows_new = pattern.match(row[1])
if rows_new.group(1) is not None:
  cursor.execute("""
  update gene set descrip = %s where descrip = %s""",
(rows_new.group(1), row[0]))
  #cursor.execute("""
  #update gene set descrip = %s where descrip = %s""",
(rows_new.group(1), row[0]))

  conn.close()


--
Regards
Boffin





On Tue, Sep 17, 2013 at 1:05 PM, Ben Finney wrote:

> Venkat Addala  writes:
>
> >   I'm new to python
>
> Welcome! Congratulations on choosing Python for programming.
>
> > i am connecting mysql database with python. now i want to do
> > sanitation on the database, like to remove "\n", extra spaces blah
> > blah.. and update it back to mysql database.
>
>
> > i was trying somthing, here is my code, can you please provide me
> > solution for this..
>
> Thank you for providing a small, complete example.
>
> You should also describe what behaviour you expect, and what behaviour
> you're getting instead. What happens, and how are you expecting it to be
> different?
>
> > #!/usr/bin/python
> > import MySQLdb as mdb
> >
> > con = mdb.connect('localhost', 'root', 'pass@123', 'workbench');
>
> There's no need to end Python statements with a semicolon; it's only
> confusing to do it.
>
> >   rows = cur.fetchall()
> >   for row in rows:
>
> You never use ‘rows’ for anything else, so you may as well forget it and
> just iterate directly over the return value::
>
> for row in cur.fetchall():
>
> > row_new = row[0].split("\n", " ")
>
> Read the documentation for ‘str.split’ to see what is wrong with the
> above call.
>
>
> You might also be interested in the ‘python-tutor’ forum, specially
> designed for beginners with basic questions about Python
> http://mail.python.org/mailman/listinfo/tutor>
> http://dir.gmane.org/gmane.comp.python.tutor>.
>
> Good hunting to you!
>
> --
>  \ “Sunday: A day given over by Americans to wishing that they |
>   `\  themselves were dead and in Heaven, and that their neighbors |
> _o__)were dead and in Hell.” —Henry L. Mencken |
> Ben Finney
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb Help

2013-09-17 Thread Ervin Hegedüs
Hello,

On Tue, Sep 17, 2013 at 12:43:20PM +0530, Venkat Addala wrote:
> Hi all,
> 
> 
>   I'm new to python, i am connecting mysql database with python. now i want
> to do sanitation on the database, like to remove "\n", extra spaces blah
> blah.. and update it back to mysql database. i was trying somthing, here is
> my code, can you please provide me solution for this..
> 
> #!/usr/bin/python
> import MySQLdb as mdb
> 
> con = mdb.connect('localhost', 'root', 'pass@123', 'workbench');

a tip: you can pass the arguments to function as dictionary, so
if you store the connection arguments anywhere, you use this
form:

conndsc = {'host': 'localhost', 'user': 'root', 'port': 3306, }
con = mdb.connect(**conndsc)

My personal opinion, but it's easyer to use the cursor if you
have dictionary-like cursor:

> with con:
>   cur = con.cursor()

cur = con.cursor(mdb.cursors.DictCursor)

In this case you can reference the name of the table column,
instead of index of result, in your example:

row['descrip']

>   cur.execute("SELECT descrip FROM table LIMIT 1")
>   rows = cur.fetchall()

if you want to fetch only one row, you can use cur.fetchrow(),
which gives only one row, and you don't need to iterate that

>   for row in rows:
> row_new = row[0].split("\n", " ")
> row = "".join(row_new)

as Benn Finney wrote, the use of split() above is wrong.
I think you need some kinf of this:

" ".join([f.strip() for f in row[0].replace("\n", " ").split()])

but it depends what you want.


Cheers:

Ervin

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


Re: MySQLdb Help

2013-09-17 Thread Ervin Hegedüs
Hello,

On Tue, Sep 17, 2013 at 05:35:30PM +1000, Ben Finney wrote:
> Venkat Addala  writes:
> 
> >   rows = cur.fetchall()
> >   for row in rows:
> 
> You never use ‘rows’ for anything else, so you may as well forget it and
> just iterate directly over the return value::
> 
> for row in cur.fetchall():

and what if in body of iteration there is another fetchall()? :)

I mean:
  for row in cur.fetchall():
do_domething()
cur.execute("SELECT * FROM another_table")


Cheers:


Ervin
 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Qt connect and first connect or unicode

2013-09-17 Thread Steven D'Aprano
On Tue, 17 Sep 2013 08:42:35 +0430, Mohsen Pahlevanzadeh wrote:

> Dear all,
> 
> Unfortunately, i confused and need help... the following code is:
> ### 
> ##CheckBox:
> QtCore.QObject.connect(self.checkBox,
> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
> self.materialsInstance.setFilterDict("C", self, "name",
> self.lineEdit.text()))


I don't use Qt, but I'll try to help.

First question, what does _fromUtf8 do? It appears to be a private 
function. Is that your function? If you want to create a string from UTF-8 
bytes, use:

some_bytes.decode('utf-8')

I don't think there is a need for a dedicated _fromUtf8 function.

If you are using Python 3, then "toggled(bool)" is already a Unicode 
string, and there is no need to convert from UTF-8.

If you are using Python 2, then "toggled(bool)" is a byte string, and you 
can turn it into a Unicode string by just using the u prefix:

u"toggled(bool)"

Again, no need to convert from UTF-8.

The only time you need to convert from UTF-8 is when you are reading data 
from a file, or other external source, that is encoded in UTF-8.

Other than that, your first line of code seems like a straight-forward 
call to set a callback function. When the button is pressed, the 
instance's attribute materialsInstance calls the method setFilterDict.


> QtCore.QObject.connect(self.checkBox_2,
> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
> self.materialsInstance.setFilterDict("C", self, "bought_price",
> persianToInteger(unicode(self.lineEdit_2.text()

Again, the same method is called, only this time with different 
arguments. Hmmm, this strikes me as poor design. I think that a better 
design would be for the object to have a few methods:

def toggle_checkbox(self, flag):
# checkbox logic goes here, e.g.
if flag:
...
else:
...

And then your callback is trivially

lambda: self.toggle_checkbox(get_state)


I'm not sure how to get the checkbox state from Qt, you will need to 
replace the "get_state" with the correct code.

That, in my opinion, is easier to understand.


> QtCore.QObject.connect(self.checkBox_4,
> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
> self.materialsInstance.setFilterDict("C",self,"stock",
> persianToInteger(unicode(self.lineEdit_3.text()

And more callbacks. Most of your code is probably irrelevant to the 
problem you are having. You will help us to help you if you can read this 
website:

http://sscce.org/


and simplify your code.


[...many more callbacks...]


>  
> Description:
> I have 3 widget:
> 1. CheckBox:  a. name b. bought_price c. stock 2. LineEdit : a. name b.
> bought_price c. stock 3. One PushButton
> 
> i have three slot: 1. responseToRequestForData()  2.setFilterDict()
> 3.unSetFilterDict()
> responseToRequestForData(): start to search in DB setFilterDict(): fill
> a dict from my LineEdit
> 
> Problem:
> My name is filled in dict but its value doesn't fill up. b and c don't
> have any problem.

I'm afraid I don't understand this. Even your followup post doesn't 
really help:

> I see same output in console:
> {'stock': 2, 'name': PyQt4.QtCore.QString(u''), 'bought_price': 23}


What result where you expecting?

If I remember correctly, Qt strings are mutable unicode strings, so 
'name' is associated with an empty Qt string. If they are mutable, that 
means that once the dict is set:

{'name': QString(u'contents of text field'), ...}


if the text field changes, so will the string. Is that what is happening?

(Or perhaps I have mis-remembered about Qt strings.)

You have two callbacks that appear to set the "name" key in the dict. 
Perhaps one of them is setting it to an empty value.




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


Re: MySQLdb Help

2013-09-17 Thread Ben Finney
Ervin Hegedüs  writes:

> Hello,
>
> On Tue, Sep 17, 2013 at 05:35:30PM +1000, Ben Finney wrote:
> > for row in cur.fetchall():
>
> and what if in body of iteration there is another fetchall()? :)

Yes, what if? Each call to ‘fetchall’ returns a sequence of rows. I
don't see your point.

-- 
 \  “The most common way people give up their power is by thinking |
  `\   they don't have any.” —Alice Walker |
_o__)  |
Ben Finney

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


HID Feature Raport, Linux

2013-09-17 Thread Kasper Jepsen
Hi,

I have been using pywinusb.hid for a hid unit, using only feature reports.
I like to get this code to run on raspbian PI, but i can not fint a good 
library to support HID/feature reports?
I am a USB newbie 
Can anyone help me, or point me in a direction to send/recieve feature reports 
without HID support?

Br.
Kasper
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb Help

2013-09-17 Thread Ervin Hegedüs
Hello,

On Tue, Sep 17, 2013 at 07:22:50PM +1000, Ben Finney wrote:
> Ervin Hegedüs  writes:
> 
> > Hello,
> >
> > On Tue, Sep 17, 2013 at 05:35:30PM +1000, Ben Finney wrote:
> > > for row in cur.fetchall():
> >
> > and what if in body of iteration there is another fetchall()? :)
> 
> Yes, what if? Each call to ‘fetchall’ returns a sequence of rows. I
> don't see your point.

yep', sorry, I'm confused. I just remember - maybe badly - once I
used this form, and the 'row' continues the new sequence... But
now I tried, and I see this presumtion is wrong.

Sorry for disturbing, and thanks :)


a.

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


Re: statsmodels.api

2013-09-17 Thread Davide Dalmasso
Il giorno lunedì 16 settembre 2013 17:47:55 UTC+2, Ethan Furman ha scritto:
> On 09/16/2013 08:37 AM, Davide Dalmasso wrote:
> 
> > Hi,
> 
> >
> 
> > I intalled an executable version of statsmodels library for Windows 32-bit.
> 
> > When I import it in my Python Shell no problem occurs buy when I write:
> 
> >
> 
> > import statsmodels.api as sm
> 
> >
> 
> > the following error arises:
> 
> >
> 
> > Traceback (most recent call last):
> 
> >File "", line 1, in 
> 
> >  import statsmodels.api
> 
> >File "C:\Python33\lib\site-packages\statsmodels\api.py", line 1, in 
> > 
> 
> >  from . import iolib, datasets, tools
> 
> >File "C:\Python33\lib\site-packages\statsmodels\iolib\__init__.py", line 
> > 1, in 
> 
> >  from .foreign import StataReader, genfromdta, savetxt
> 
> >File "C:\Python33\lib\site-packages\statsmodels\iolib\foreign.py", line 
> > 20, in 
> 
> >  import statsmodels.tools.data as data_util
> 
> >File "C:\Python33\lib\site-packages\statsmodels\tools\__init__.py", line 
> > 1, in 
> 
> >  from .tools import add_constant, categorical
> 
> >File "C:\Python33\lib\site-packages\statsmodels\tools\tools.py", line 8, 
> > in 
> 
> >  from scipy.interpolate import interp1d
> 
> >File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 
> > 150, in 
> 
> >  from .interpolate import *
> 
> >File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", 
> > line 12, in 
> 
> >  import scipy.special as spec
> 
> >File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 
> > 529, in 
> 
> >  from ._ufuncs import *
> 
> 
> 
> We'll need the rest of the traceback, as it will have the actual error.
> 
> 
> 
> --
> 
> ~Ethan~

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit 
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import statsmodels.api as sm
Traceback (most recent call last):
  File "", line 1, in 
import statsmodels.api as sm
  File "C:\Python33\lib\site-packages\statsmodels\api.py", line 1, in 
from . import iolib, datasets, tools
  File "C:\Python33\lib\site-packages\statsmodels\iolib\__init__.py", line 1, 
in 
from .foreign import StataReader, genfromdta, savetxt
  File "C:\Python33\lib\site-packages\statsmodels\iolib\foreign.py", line 20, 
in 
import statsmodels.tools.data as data_util
  File "C:\Python33\lib\site-packages\statsmodels\tools\__init__.py", line 1, 
in 
from .tools import add_constant, categorical
  File "C:\Python33\lib\site-packages\statsmodels\tools\tools.py", line 8, in 

from scipy.interpolate import interp1d
  File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 150, 
in 
from .interpolate import *
  File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 
12, in 
import scipy.special as spec
  File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, in 

from ._ufuncs import *
ImportError: DLL load failed: Impossibile trovare il modulo specificato.
>>>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Qt connect and first connect or unicode

2013-09-17 Thread Vincent Vande Vyvre

Le 17/09/2013 11:05, Steven D'Aprano a écrit :

On Tue, 17 Sep 2013 08:42:35 +0430, Mohsen Pahlevanzadeh wrote:


Dear all,

Unfortunately, i confused and need help... the following code is:
###
##CheckBox:
 QtCore.QObject.connect(self.checkBox,
QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
self.materialsInstance.setFilterDict("C", self, "name",
self.lineEdit.text()))


I don't use Qt, but I'll try to help.

First question, what does _fromUtf8 do? It appears to be a private
function. Is that your function? If you want to create a string from UTF-8
bytes, use:

some_bytes.decode('utf-8')

I don't think there is a need for a dedicated _fromUtf8 function.

If you are using Python 3, then "toggled(bool)" is already a Unicode
string, and there is no need to convert from UTF-8.

If you are using Python 2, then "toggled(bool)" is a byte string, and you
can turn it into a Unicode string by just using the u prefix:

u"toggled(bool)"

Again, no need to convert from UTF-8.

The only time you need to convert from UTF-8 is when you are reading data
from a file, or other external source, that is encoded in UTF-8.

Other than that, your first line of code seems like a straight-forward
call to set a callback function. When the button is pressed, the
instance's attribute materialsInstance calls the method setFilterDict.



 QtCore.QObject.connect(self.checkBox_2,
QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
self.materialsInstance.setFilterDict("C", self, "bought_price",
persianToInteger(unicode(self.lineEdit_2.text()

Again, the same method is called, only this time with different
arguments. Hmmm, this strikes me as poor design. I think that a better
design would be for the object to have a few methods:

 def toggle_checkbox(self, flag):
 # checkbox logic goes here, e.g.
 if flag:
 ...
 else:
 ...

And then your callback is trivially

lambda: self.toggle_checkbox(get_state)


I'm not sure how to get the checkbox state from Qt, you will need to
replace the "get_state" with the correct code.

That, in my opinion, is easier to understand.



 QtCore.QObject.connect(self.checkBox_4,
QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
self.materialsInstance.setFilterDict("C",self,"stock",
persianToInteger(unicode(self.lineEdit_3.text()

And more callbacks. Most of your code is probably irrelevant to the
problem you are having. You will help us to help you if you can read this
website:

http://sscce.org/


and simplify your code.


[...many more callbacks...]




Description:
I have 3 widget:
1. CheckBox:  a. name b. bought_price c. stock 2. LineEdit : a. name b.
bought_price c. stock 3. One PushButton

i have three slot: 1. responseToRequestForData()  2.setFilterDict()
3.unSetFilterDict()
responseToRequestForData(): start to search in DB setFilterDict(): fill
a dict from my LineEdit

Problem:
My name is filled in dict but its value doesn't fill up. b and c don't
have any problem.

I'm afraid I don't understand this. Even your followup post doesn't
really help:


I see same output in console:
{'stock': 2, 'name': PyQt4.QtCore.QString(u''), 'bought_price': 23}


What result where you expecting?

If I remember correctly, Qt strings are mutable unicode strings, so
'name' is associated with an empty Qt string. If they are mutable, that
means that once the dict is set:

{'name': QString(u'contents of text field'), ...}


if the text field changes, so will the string. Is that what is happening?

(Or perhaps I have mis-remembered about Qt strings.)

You have two callbacks that appear to set the "name" key in the dict.
Perhaps one of them is setting it to an empty value.






_fromUtf8 is needed for the API compatibility, at the beginning of the code of 
Moshen it is these lines:

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s


Moshen, I thing if you pass the instance of your GUI at the class 
materialsInstance you'll can simplify your connections

self.lineEdit.returnPressed.connect(self.materialsInstance.responseToRequestForData)
self.lineEdit.editingFinnished.connect(self.materialsInstance.responseToRequestForData)

For the checkBoxes, I'm not sure you need all these arguments but I don't know 
enough your code.


--
Vincent V.V.
Oqapy  . Qarte 
 . PaQager 

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


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread Heiko Wundram
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Am 17.09.2013 01:41, schrieb Steven D'Aprano:
> I cannot fathom for the life of me a legitimate reason for your
> website to use a fake IP address and hostname when sending email.

In addition to that: it's amazing that Nikos thinks TCP will still
work in the presence of spoofed IP addresses. Email without TCP is a
challenge, at the least.

- -- 
- --- Heiko.
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.20 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSODMPAAoJEDMqpHf921/SC0YH/3rCWDcX+rzJKonfeJXUYNxz
nbrBPDsoZf6xPh0socOn88TrzgbZewhWf2l3dHAPOKxTAwUWjRjygatTccBmZur9
6B+t410Nq7axz5+0jg4OwBSOQVt3jr0YInK3vWzq4nd0V0cHchvZzfrdSmnEloDU
V3wIPhBM7MEavyuvrxhutIM8DxA/0z6L/cLhwnpHfE6AxVMeGh/dHhGK9eaxJ03C
pfPWgb2fuCRHrOd3+cLUx3ZFF6YkK00PZzICFhkx236K8iaTvBgqIsod2tpyP6+t
H9qlXCfxit1d6nEzTJavx4suBGStcbhDr1C6VlDaPjfVH+w8842h/0QLhTsMXjY=
=K/XL
-END PGP SIGNATURE-
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weird ttk behaviour

2013-09-17 Thread Rotwang

On 16/09/2013 19:43, Serhiy Storchaka wrote:

16.09.13 19:28, Rotwang написав(ла):

On Windows 7 (sys.version is '3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012,
10:57:17) [MSC v.1600 64 bit (AMD64)]') there's no problem; f() works
fine in the first place. Does anybody know what's going on?


What _root.wantobjects() returns?


It returns True, both before and after the call to 
style.theme_use('newtheme'). Why do you ask? I've no idea what 
Tk.wantobjects is supposed to do (I tried help() and some web searches 
with no luck).


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


Is this a bug in Python 3.3?

2013-09-17 Thread Aseem Bansal
While using IDLE I used the license() function to see the license information. 
In it there was a list of all the versions and from which version they are 
derived is written.

The list goes upto 3.3.1 but doesn't include 3.3.2. Is that a minor bug or is 
the current version not mentioned in that list?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weird ttk behaviour

2013-09-17 Thread Rotwang

On 16/09/2013 23:34, Chris Angelico wrote:

On Tue, Sep 17, 2013 at 2:28 AM, Rotwang  wrote:

If I then uncomment those two lines, reload the module and call f() again
(by entering tkderp.reload(tkderp).f()), the function works like it was
supposed to in the first place: two warnings, no exceptions. I can reload
the module as many times as I like and f() will continue to work without any
problems.


Reloading modules in Python is a bit messy. Are you able to tinker
with it and make it work in some way without reloading? It'd be easier
to figure out what's going on that way.


I can't think what else I could try, do you have any suggestions? The 
problem first appeared in a much larger module (I was trying to replace 
some tkinter widgets that looked bad on Linux with their ttk 
equivalents); the only reason I noticed the thing about reloading is 
that I was trying to reproduce the error in a short module by repeatedly 
making changes and reloading.

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


Re: Weird ttk behaviour

2013-09-17 Thread Chris Angelico
On Tue, Sep 17, 2013 at 9:27 PM, Rotwang  wrote:
> On 16/09/2013 23:34, Chris Angelico wrote:
>>
>> On Tue, Sep 17, 2013 at 2:28 AM, Rotwang  wrote:
>>>
>>> If I then uncomment those two lines, reload the module and call f() again
>>> (by entering tkderp.reload(tkderp).f()), the function works like it was
>>> supposed to in the first place: two warnings, no exceptions. I can reload
>>> the module as many times as I like and f() will continue to work without
>>> any
>>> problems.
>>
>>
>> Reloading modules in Python is a bit messy. Are you able to tinker
>> with it and make it work in some way without reloading? It'd be easier
>> to figure out what's going on that way.
>
>
> I can't think what else I could try, do you have any suggestions? The
> problem first appeared in a much larger module (I was trying to replace some
> tkinter widgets that looked bad on Linux with their ttk equivalents); the
> only reason I noticed the thing about reloading is that I was trying to
> reproduce the error in a short module by repeatedly making changes and
> reloading.

If reloading and doing it again makes things different, what happens
if you simply trigger your code twice without reloading?

I've no idea if it'll help, it just seems like an attack vector on the
problem, so to speak.

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


Re: statsmodels.api

2013-09-17 Thread Oscar Benjamin
On 17 September 2013 11:10, Davide Dalmasso  wrote:
> Il giorno lunedì 16 settembre 2013 17:47:55 UTC+2, Ethan Furman ha scritto:
>>
>> We'll need the rest of the traceback, as it will have the actual error.
>>
> Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit 
> (Intel)] on win32
> Type "copyright", "credits" or "license()" for more information.
 import statsmodels.api as sm
> Traceback (most recent call last):
>   File "", line 1, in 
> import statsmodels.api as sm
>   File "C:\Python33\lib\site-packages\statsmodels\api.py", line 1, in 
> from . import iolib, datasets, tools
>   File "C:\Python33\lib\site-packages\statsmodels\iolib\__init__.py", line 1, 
> in 
> from .foreign import StataReader, genfromdta, savetxt
>   File "C:\Python33\lib\site-packages\statsmodels\iolib\foreign.py", line 20, 
> in 
> import statsmodels.tools.data as data_util
>   File "C:\Python33\lib\site-packages\statsmodels\tools\__init__.py", line 1, 
> in 
> from .tools import add_constant, categorical
>   File "C:\Python33\lib\site-packages\statsmodels\tools\tools.py", line 8, in 
> 
> from scipy.interpolate import interp1d
>   File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 
> 150, in 
> from .interpolate import *
>   File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 
> 12, in 
> import scipy.special as spec
>   File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, 
> in 
> from ._ufuncs import *
> ImportError: DLL load failed: Impossibile trovare il modulo specificato.


This looks like a bug in your scipy installation. What happens if you
try the following in an interactive session:

>>> import scipy
>>> from scipy.interpolate import interp1d

Also how did you install scipy? I didn't think that Windows binaries
for Python 3.3 were available yet.


Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread Joel Goldstick
In honour of the value of mailing lists in general lets stop this thread
since once again the troll pattern repeats ad infinitum.

At least if you want to add to this nonsense, read each of the (several?)
dozen entries.

1. a seemingly earnest question is asked with something to do with python.
The question looks like it is from an very anxious novice
2. errors are pointed out in the sloppiness of the code and as an aside,
the value of code in general is questioned since it is based on assumptions
that are completely muddled, misunderstood
3. people start to laugh and grouse "here we go again"
4. The troll whines back that he asked a good and question and people are
being mean to him
5. He draws more people into the thread who feel bad he was maligned.
6. the thread seems to go on with some (faux) value as people probe the the
basis of the discussion further
7. The troll, ignores every single bit of useful information provided that
doesn't serve his interest in keeping this going by slightly altering the
questions, or posing new variants, or raising hair-brain notions.  In other
words he is not discussion his own question, he is TROLLING to keep the
thread alive.
8. Someone notices the cycle is complete.

Go back for a year to every question asked by the troll who goes by Nikos
or Ferrous, or 2 or three other email address (in the same thread!) and see
if any of them don't follow this pattern.  If you are new here and think
this guy is worth your time, you are wasting everyone's time and memory
space or disk space to add to these threads

Ok, I won't do it again.


On Tue, Sep 17, 2013 at 6:46 AM, Heiko Wundram wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> Am 17.09.2013 01:41, schrieb Steven D'Aprano:
> > I cannot fathom for the life of me a legitimate reason for your
> > website to use a fake IP address and hostname when sending email.
>
> In addition to that: it's amazing that Nikos thinks TCP will still
> work in the presence of spoofed IP addresses. Email without TCP is a
> challenge, at the least.
>
> - --
> - --- Heiko.
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v2.0.20 (MingW32)
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iQEcBAEBAgAGBQJSODMPAAoJEDMqpHf921/SC0YH/3rCWDcX+rzJKonfeJXUYNxz
> nbrBPDsoZf6xPh0socOn88TrzgbZewhWf2l3dHAPOKxTAwUWjRjygatTccBmZur9
> 6B+t410Nq7axz5+0jg4OwBSOQVt3jr0YInK3vWzq4nd0V0cHchvZzfrdSmnEloDU
> V3wIPhBM7MEavyuvrxhutIM8DxA/0z6L/cLhwnpHfE6AxVMeGh/dHhGK9eaxJ03C
> pfPWgb2fuCRHrOd3+cLUx3ZFF6YkK00PZzICFhkx236K8iaTvBgqIsod2tpyP6+t
> H9qlXCfxit1d6nEzTJavx4suBGStcbhDr1C6VlDaPjfVH+w8842h/0QLhTsMXjY=
> =K/XL
> -END PGP SIGNATURE-
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Having both if() and for() statements in one liner

2013-09-17 Thread Ferrous Cranus

o want to avoid having to type somehting like this:

if person="George":
times in range(0, 5):


Why it gives me an error when i'm trying to write it like this:


if person="George" for times in range(0, 5):

Can't i ahve both if and for in a one liner?
--
https://mail.python.org/mailman/listinfo/python-list


error python-gammu

2013-09-17 Thread Tal Raveh
Hello,

I just install gammu and try to : import gammu
and i get error:

Traceback (most recent call last):
  File "./pygammu.py", line 4, in 
import gammu
  File "/usr/lib64/python2.6/site-packages/gammu/__init__.py", line 65, in

from gammu._gammu import *
ImportError: /usr/lib64/python2.6/site-packages/gammu/_gammu.so: undefined
symbol: DivertCallTypeFromString

some one know whats wrong ?

Best Regards,
Tal
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread Ferrous Cranus

Στις 17/9/2013 2:55 μμ, ο/η Joel Goldstick έγραψε:

In honour of the value of mailing lists in general lets stop this thread
since once again the troll pattern repeats ad infinitum.

At least if you want to add to this nonsense, read each of the
(several?) dozen entries.

1. a seemingly earnest question is asked with something to do with
python.  The question looks like it is from an very anxious novice
2. errors are pointed out in the sloppiness of the code and as an aside,
the value of code in general is questioned since it is based on
assumptions that are completely muddled, misunderstood
3. people start to laugh and grouse "here we go again"
4. The troll whines back that he asked a good and question and people
are being mean to him
5. He draws more people into the thread who feel bad he was maligned.
6. the thread seems to go on with some (faux) value as people probe the
the basis of the discussion further
7. The troll, ignores every single bit of useful information provided
that doesn't serve his interest in keeping this going by slightly
altering the questions, or posing new variants, or raising hair-brain
notions.  In other words he is not discussion his own question, he is
TROLLING to keep the thread alive.
8. Someone notices the cycle is complete.

Go back for a year to every question asked by the troll who goes by
Nikos or Ferrous, or 2 or three other email address (in the same
thread!) and see if any of them don't follow this pattern.  If you are
new here and think this guy is worth your time, you are wasting
everyone's time and memory space or disk space to add to these threads

Ok, I won't do it again.


Yes you are doing it.
I'm not trolling but trying to solve a specific question and i have 
provided code i wrote to do that and explained the reason of why i want 
it to work like this.

I wouldn't waste my time trying code so many days until i make it work.

If you want to think i'm trolling go ahead and do it but please do it in 
your own thread not messing up mines.


There are members here like Tim Chase who said that they find it 
interesting to be able to do what i proposed.


It's ok if you dont want to help, but spamming my thread with your 
trolling assumptions towards me is tiresome and if you gonna do it open 
do it at least in your own thread.


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


Re: statsmodels.api

2013-09-17 Thread Davide Dalmasso

You are right... there is a problem with scipy intallation because this error 
arise...

>>> from scipy.interpolate import interp1d
Traceback (most recent call last):
  File "", line 1, in 
from scipy.interpolate import interp1d
  File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 150, 
in 
from .interpolate import *
  File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 
12, in 
import scipy.special as spec
  File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, in 

from ._ufuncs import *
ImportError: DLL load failed: Impossibile trovare il modulo specificato.

I tryed to re-install the scipy executable that I downloaded from 
http://www.lfd.uci.edu/~gohlke/pythonlibs/
but the problem persists
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: statsmodels.api

2013-09-17 Thread Davide Dalmasso
On Monday, 16 September 2013 17:37:58 UTC+2, Davide Dalmasso  wrote:
> Hi,
> 
> 
> 
> I intalled an executable version of statsmodels library for Windows 32-bit.
> 
> When I import it in my Python Shell no problem occurs buy when I write:
> 
> 
> 
> import statsmodels.api as sm
> 
> 
> 
> the following error arises:
> 
> 
> 
> Traceback (most recent call last):
> 
>   File "", line 1, in 
> 
> import statsmodels.api
> 
>   File "C:\Python33\lib\site-packages\statsmodels\api.py", line 1, in 
> 
> from . import iolib, datasets, tools
> 
>   File "C:\Python33\lib\site-packages\statsmodels\iolib\__init__.py", line 1, 
> in 
> 
> from .foreign import StataReader, genfromdta, savetxt
> 
>   File "C:\Python33\lib\site-packages\statsmodels\iolib\foreign.py", line 20, 
> in 
> 
> import statsmodels.tools.data as data_util
> 
>   File "C:\Python33\lib\site-packages\statsmodels\tools\__init__.py", line 1, 
> in 
> 
> from .tools import add_constant, categorical
> 
>   File "C:\Python33\lib\site-packages\statsmodels\tools\tools.py", line 8, in 
> 
> 
> from scipy.interpolate import interp1d
> 
>   File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 
> 150, in 
> 
> from .interpolate import *
> 
>   File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 
> 12, in 
> 
> import scipy.special as spec
> 
>   File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, 
> in 
> 
> from ._ufuncs import *
> 
> 
> 
> Why?
> 
> 
> 
> Thanks for any help you will want to give me!
> 
> 
> 
> Davide
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread Heiko Wundram
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Am 17.09.2013 13:55, schrieb Joel Goldstick:
> At least if you want to add to this nonsense, read each of the
> (several?) dozen entries.

Actually, I have read each of the troll cycles (just as I read much of
clp, although I haven't participated much for the last five years),
and found most of them to be rather interesting reads (in their
digression from the original topic).

And: I actually find it rather valuable answering indirectly to things
noticed "along the ride" (or reading what other people answer
indirectly in the same manner) - see my post in this thread where I
pointed out that the original code actually does not sanitize inputs
to a shell command to send mail.

But, again, your impression may differ, and I can respect that.

- -- 
- --- Heiko.
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.20 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSOEl/AAoJEDMqpHf921/SAJQIAI48Kzz0js1QqMDkotmMZfdE
XJYwsWlRXtaPhRy1VEGKHiSgCEd71/IVDUOPEv5TuJMy9zfsW1McexrYMW0NW63J
RiAlDmLSITfdPRYqPgmOTA4MqgJ3V2/oAzOpYXwPqs8Qdt92AX5Tr5itDFgua18T
TSdsD4gNudtIMUBkACzMjJKGyxrHvFFhGpUHlFh5swrZhflaGm1TuCWwz3ojTSbG
yoQRPe1ylSjcxkJesaKXR8mIaUMq4mrUaChBe+FwoCJXXs8kkX/EO3KULvKCxQGU
lzsom+b/eTaxB/ttyHwbt7QSsYq1ko2fIeqqDD/jmhTpg5gshOC+JHLs3bUkmMw=
=sTJq
-END PGP SIGNATURE-
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is %z broken for return values of time.gmtime()?

2013-09-17 Thread random832
On Mon, Sep 16, 2013, at 16:55, Michael Schwarz wrote:
> On 2013-W38-1, at 19:56, [email protected] wrote:
> 
> > On Mon, Sep 16, 2013, at 9:15, Michael Schwarz wrote:
> >> According to the documentation of time.gmtime(), it returns a struct_time
> >> in UTC, but %z is replaced by +0100, which is the UTC offset of my OS’s
> >> time zone without DST, but DST is currently in effect here (but was not
> >> at the timestamp passed to gmtime()).
> > 
> > The struct_time type does not include information about what timezone it
> > is in.
> 
> Uhm … Python 3.3 introduced the tm_gmtoff member of struct_time, which
> contains the offset to UTC.

I don't see it. Maybe it is not available on platforms that do not
provide it? Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53)
[MSC v.1600 64 bit (AMD64)] on win32)

I would argue that it _should_ be, and that it should populate it with 0
in gmtime or either with timezone/altzone or by some sort of reverse
calculation in localtime, but it is not. Another problem to add to my
list of reasons for my recent python-ideas proposal.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread Robert Kern

On 2013-09-17 13:11, Ferrous Cranus wrote:


There are members here like Tim Chase who said that they find it interesting to
be able to do what i proposed.


No, he didn't. He was using sarcasm in a vain attempt to inspire you to search 
the Python documentation where you could easily find the standard SMTP library.


  http://docs.python.org/2/library/smtplib

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: Having both if() and for() statements in one liner

2013-09-17 Thread Robert Kern

On 2013-09-17 13:02, Ferrous Cranus wrote:

o want to avoid having to type somehting like this:

if person="George":
 times in range(0, 5):


Why it gives me an error when i'm trying to write it like this:


if person="George" for times in range(0, 5):

Can't i ahve both if and for in a one liner?


Not in Python, no.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: Having both if() and for() statements in one liner

2013-09-17 Thread Roy Smith
In article ,
 Ferrous Cranus  wrote:

> o want to avoid having to type somehting like this:
> 
> if person="George":
>   times in range(0, 5):
> 
> 
> Why it gives me an error when i'm trying to write it like this:
> 
> 
> if person="George" for times in range(0, 5):

Step One when reporting a problem is don't just tell us you got an 
error.  Tell us what the error is.  Cut and paste the exact text of the 
full error message.

Although, in this case, it's pretty easy to guess that it was a syntax 
error :-)

I'm not sure where to start.  First, the '=' in 'person="George"' should 
be '=='.  In Python, '=' is used for assignment, '==' is used for 
equality testing.

Next, if you want to use the 1-line version of 'if', you need a ':' 
after the condition.  Something like:

if person == 'George': print 'foo'

but it's generally considered poor style to use 1-line if statements.  
Just write it on two lines:

if person == 'George':
print 'foo'

They just discovered a huge newline vein in Montana and they're mining 
the things like crazy.  There's no shortage of them so feel free to use 
as many as you like.  They even get recycled.

But, I'm not even sure you can put a 'for' statement as the body of a 
1-line 'if'.  I've never tried it before, and my one experiment now got 
me a syntax error.  Even if it turns out to be legal and I just haven't 
got the details right, it's just The Wrong Thing To Do.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: statsmodels.api

2013-09-17 Thread Oscar Benjamin
On 17 September 2013 13:13, Davide Dalmasso  wrote:
>
> You are right... there is a problem with scipy intallation because this error 
> arise...
>
 from scipy.interpolate import interp1d
> Traceback (most recent call last):
>   File "", line 1, in 
> from scipy.interpolate import interp1d
>   File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 
> 150, in 
> from .interpolate import *
>   File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 
> 12, in 
> import scipy.special as spec
>   File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, 
> in 
> from ._ufuncs import *
> ImportError: DLL load failed: Impossibile trovare il modulo specificato.
>
> I tryed to re-install the scipy executable that I downloaded from 
> http://www.lfd.uci.edu/~gohlke/pythonlibs/
> but the problem persists

There are potential compatibility problems with the binaries from
there as described at the top of the page. One thing is that you need
to use Christopher's own numpy build to go with scipy:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
If you installed numpy from somewhere else then that could be your problem.

Essentially scipy isn't quite ported to Python 3.3 yet so my general
advice is to use Python 3.2 and to use the official numpy/scipy
binaries from sourceforge (they don't yet provide binaries for 3.3).

Alternatively an easier approach might be to use Python(x, y) (which
is free) or the Enthought Python Distribution (which is free for
academic users). These are distributions that bundle Python with
numpy/scipy and lots of other packages. I think they both still use
Python 2.7 though.

(As an aside, this is all much simpler if you're using Ubuntu or some
other Linux distro rather than Windows.)


Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: statsmodels.api

2013-09-17 Thread Josef Pktd
On Tuesday, September 17, 2013 8:13:27 AM UTC-4, Davide Dalmasso wrote:
> You are right... there is a problem with scipy intallation because this error 
> arise...
> 
> 
> 
> >>> from scipy.interpolate import interp1d
> 
> Traceback (most recent call last):
> 
>   File "", line 1, in 
> 
> from scipy.interpolate import interp1d
> 
>   File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 
> 150, in 
> 
> from .interpolate import *
> 
>   File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 
> 12, in 
> 
> import scipy.special as spec
> 
>   File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, 
> in 
> 
> from ._ufuncs import *
> 
> ImportError: DLL load failed: Impossibile trovare il modulo specificato.
> 
> 
> 
> I tryed to re-install the scipy executable that I downloaded from 
> http://www.lfd.uci.edu/~gohlke/pythonlibs/
> 
> but the problem persists

Did you also install numpy from gohlke?
My guess would be binary incompatibility if numpy is not the MKL version.

Josef
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Having both if() and for() statements in one liner

2013-09-17 Thread Ferrous Cranus

Στις 17/9/2013 4:00 μμ, ο/η Roy Smith έγραψε:

In article ,
  Ferrous Cranus  wrote:


o want to avoid having to type somehting like this:

if person="George":
times in range(0, 5):


Why it gives me an error when i'm trying to write it like this:


if person="George" for times in range(0, 5):


Step One when reporting a problem is don't just tell us you got an
error.  Tell us what the error is.  Cut and paste the exact text of the
full error message.

Although, in this case, it's pretty easy to guess that it was a syntax
error :-)

I'm not sure where to start.  First, the '=' in 'person="George"' should
be '=='.  In Python, '=' is used for assignment, '==' is used for
equality testing.

Next, if you want to use the 1-line version of 'if', you need a ':'
after the condition.  Something like:

 if person == 'George': print 'foo'

but it's generally considered poor style to use 1-line if statements.
Just write it on two lines:

 if person == 'George':
 print 'foo'

They just discovered a huge newline vein in Montana and they're mining
the things like crazy.  There's no shortage of them so feel free to use
as many as you like.  They even get recycled.

But, I'm not even sure you can put a 'for' statement as the body of a
1-line 'if'.  I've never tried it before, and my one experiment now got
me a syntax error.  Even if it turns out to be legal and I just haven't
got the details right, it's just The Wrong Thing To Do.




I just want to say tot he program that

that only run the for statement if and only if person=='George'

I dont see nay reason as to why this fails

perhaps like:

for times in range(0, 5) if person=='George':

but that fails too...
there must be written on soem way.


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


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread Antoon Pardon
Op 17-09-13 14:11, Ferrous Cranus schreef:

> Yes you are doing it.
> I'm not trolling but trying to solve a specific question and i have
> provided code i wrote to do that and explained the reason of why i want
> it to work like this.

No you haven't. You have given no explanation at all for why you want
to eliminate those headers.

Since those headers are added to ease finding the source of email abuse
I really am curious to know your motivation for wanting them removed.

> I wouldn't waste my time trying code so many days until i make it work.
> 
> If you want to think i'm trolling go ahead and do it but please do it in
> your own thread not messing up mines.

You are incosiderate by messing up the python list with non python
questions. Yet you demand others to be considerate by not messing up
your thread. Well you can hope I guess.

> There are members here like Tim Chase who said that they find it
> interesting to be able to do what i proposed.

Tim Chase said no such thing.

> It's ok if you dont want to help, but spamming my thread with your
> trolling assumptions towards me is tiresome and if you gonna do it open
> do it at least in your own thread.

We find it tiresome that you keep coming here with non-python
questions. That doesn't seem to stop you. So why do you think it should
stop others?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: statsmodels.api

2013-09-17 Thread Josef Pktd
On Tuesday, September 17, 2013 9:06:59 AM UTC-4, Oscar Benjamin wrote:
> On 17 September 2013 13:13, Davide Dalmasso  wrote:
> 
> >
> 
> > You are right... there is a problem with scipy intallation because this 
> > error arise...
> 
> >
> 
>  from scipy.interpolate import interp1d
> 
> > Traceback (most recent call last):
> 
> >   File "", line 1, in 
> 
> > from scipy.interpolate import interp1d
> 
> >   File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 
> > 150, in 
> 
> > from .interpolate import *
> 
> >   File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", 
> > line 12, in 
> 
> > import scipy.special as spec
> 
> >   File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, 
> > in 
> 
> > from ._ufuncs import *
> 
> > ImportError: DLL load failed: Impossibile trovare il modulo specificato.
> 
> >
> 
> > I tryed to re-install the scipy executable that I downloaded from 
> > http://www.lfd.uci.edu/~gohlke/pythonlibs/
> 
> > but the problem persists
> 
> 
> 
> There are potential compatibility problems with the binaries from
> 
> there as described at the top of the page. One thing is that you need
> 
> to use Christopher's own numpy build to go with scipy:
> 
> http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
> 
> If you installed numpy from somewhere else then that could be your problem.
> 
> 
> 
> Essentially scipy isn't quite ported to Python 3.3 yet so my general
> 
> advice is to use Python 3.2 and to use the official numpy/scipy
> 
> binaries from sourceforge (they don't yet provide binaries for 3.3).
> 
> 
> 
> Alternatively an easier approach might be to use Python(x, y) (which
> 
> is free) or the Enthought Python Distribution (which is free for
> 
> academic users). These are distributions that bundle Python with
> 
> numpy/scipy and lots of other packages. I think they both still use
> 
> Python 2.7 though.
> 
> 
> 
> (As an aside, this is all much simpler if you're using Ubuntu or some
> 
> other Linux distro rather than Windows.)

scientific python on a stick

https://code.google.com/p/winpython/wiki/PackageIndex_33

I haven't seen any problems so far on python 3.3
The statsmodels test suite passes without problems on python 3.3 also, as far 
as I remember.
(and no problems using Windows. just use the right binaries.)

Josef

> 
> 
> 
> 
> 
> Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Having both if() and for() statements in one liner

2013-09-17 Thread Heiko Wundram
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Am 17.09.2013 15:21, schrieb Ferrous Cranus:
> ... there must be written on soem way.

You've already given yourself the answer in the initial post. The
Python way to write this is:

if person == "George":
for times in range(5):
...

Why not just use what works and get some actual work done?

- -- 
- --- Heiko.
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.20 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSOF0gAAoJEDMqpHf921/Sv0oH/AyuaOk5sFlx4j7CKzv4Bb9i
+REyAtLJXpgcziviFXjIbnPsNLtGqMU6yOgp9OV7LGwfn0mnZtmI+SoYp08t7G9U
3WSMC6BOCugg419EEMmf+Gkf4fWvv/aZYWBTd8MhyiJLsQ9R7Sg9LlGYheDQ6m+S
RwWpYSHYCaJu3iy2xBJ+8AqQjOqACcMREtW1Rt1uHiydO93Dn2Abm0XLq11psYeR
OV3sftEJ2EpMEcR4I/HLx95KWIh7wvQcZywTF9y+pe1uOnLrKW/1NdkUxNdkMofy
RBNOjYJjT9JAnB2UHI1wVtbipwSi4A4zIIYsE6exv4s1IjnInrVERdDOOlqjwzQ=
=rxPO
-END PGP SIGNATURE-
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: better and user friendly IDE recommended?

2013-09-17 Thread rusi
On Wednesday, September 11, 2013 7:44:04 PM UTC+5:30, mnishpsyched wrote:
> Hey i am a programmer but new to python. Can anyone guide me in knowing which 
> is a better IDE used to develop web related apps that connect to DB using 
> python?

Just saw this
http://www.youtube.com/watch?v=1-dUkyn_fZA

Yeah... scientific programming and web programming are hardly the same :-)
Still it might be worth 20 minutes of your time
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: statsmodels.api

2013-09-17 Thread Oscar Benjamin
On 17 September 2013 14:35, Josef Pktd  wrote:
>> (As an aside, this is all much simpler if you're using Ubuntu or some
>> other Linux distro rather than Windows.)
>
> scientific python on a stick
>
> https://code.google.com/p/winpython/wiki/PackageIndex_33

Thanks, I've just installed that and I'll try it out later.

> I haven't seen any problems so far on python 3.3
> The statsmodels test suite passes without problems on python 3.3 also, as far 
> as I remember.
> (and no problems using Windows. just use the right binaries.)

Well that's exactly my point. On a Linux distro you would have the
right binaries first time. No need to search through project webpages
or documentation, weigh up different installers, or download 750MB of
software that you mostly won't use. Similarly on a Linux distro it's a
lot easier to get all of the build tools set up to build these things
from source if you'd prefer.

Windows users are often dependent on inconsistent sources of binaries.
In this case I imagine that the OP installed numpy from sourceforge
since it has 3.3 binaries but it doesn't have the same for scipy at
which point googling would easily lead to Cristoph's page.


Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Having both if() and for() statements in one liner

2013-09-17 Thread Tim Chase
On 2013-09-17 16:21, Ferrous Cranus wrote:
> I just want to say tot he program that
> 
> that only run the for statement if and only if person=='George'
> 
> I dont see nay reason as to why this fails
> 
> perhaps like:
> 
> for times in range(0, 5) if person=='George':
> 
> but that fails too...
> there must be written on soem way.

The canonical way to do this is the obvious:

  if person == "George":
for times in range(0, 5):
  ...

That said, you can do stupid things to abstract the logic like

  def iterate_if(condition, iterable):
if condition:
  for item in iterable:
yield item

which you can use something like

  for times in iterate_if(person == "George", range(0,5)):
...

but I don't advise it.  Mainly, because the iterable will be
evaluated when passed as an argument, which incurs the runtime cost.
In the canonical form, if the test isn't passed, the range(n,m) is
never even evaluated.

-tkc




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


Re: Weird ttk behaviour

2013-09-17 Thread Rotwang

On 17/09/2013 12:32, Chris Angelico wrote:

[...]

If reloading and doing it again makes things different, what happens
if you simply trigger your code twice without reloading?

I've no idea if it'll help, it just seems like an attack vector on the
problem, so to speak.


Thanks for the suggestion, here's what I've found with some more 
testing. If I rewrite the function f() like this:


def f(fail):
style = ttk.Style(_root)
style.theme_create('newtheme', parent = 'default')
tk.messagebox.showwarning('test', 'test')
if fail:
style.theme_use('newtheme')
tk.messagebox.showwarning('test', 'test')


then I import the module and call f(False) followed by f(True), the 
second call raises an exception just like the original function. I've 
tried variations of the above, such as defining a module-level global 
style instead of having one created during the function call, and the 
end result is always the same. However, suppose instead I define two 
modules, tkderp and tkderp2; both have a function f as defined in my OP, 
but the first has the last two lines of f commented out, and the second 
doesn't (i.e. tkderp is the modified tkderp from before, and tkderp2 is 
the original). Then I do this:


>>> import tkderp
>>> tkderp.f()
>>> import tkderp2
>>> tkderp2.f()


In that case the second call to f() works fine - two warnings, no 
exception. In fact, if I replace tkderp with this:


# begin tkderp.py

import tkinter as tk

_root = tk.Tk()
_root.withdraw()

# end tkderp.py


then simply importing tkderp before tkderp2 is enough to make the latter 
work properly - this


>>> import tkderp2
>>> tkderp2.f()


raises an exception, but this

>>> import tkderp
>>> import tkderp2
>>> tkderp2.f()


doesn't. Any ideas what may be going on?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Weird ttk behaviour

2013-09-17 Thread Chris Angelico
On Wed, Sep 18, 2013 at 12:25 AM, Rotwang  wrote:
> In fact, if I replace tkderp with this:
>
>
> # begin tkderp.py
>
> import tkinter as tk
>
> _root = tk.Tk()
> _root.withdraw()
>
> # end tkderp.py
>
>
> then simply importing tkderp before tkderp2 is enough to make the latter
> work properly

Nice piece of detective work! Alas, I don't know tkinter well enough
to help with the details, but this is exactly what I'd like to hear if
I were trying to pick this up and debug it :)

Tkinter experts, anywhere? Where's Ranting Rick when you need him...

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


Re: Having both if() and for() statements in one liner

2013-09-17 Thread Joel Goldstick
On Tue, Sep 17, 2013 at 10:17 AM, Tim Chase
wrote:

> On 2013-09-17 16:21, Ferrous Cranus wrote:
> > I just want to say tot he program that
> >
> > that only run the for statement if and only if person=='George'
> >
> > I dont see nay reason as to why this fails
> >
> > perhaps like:
> >
> > for times in range(0, 5) if person=='George':
> >
> > but that fails too...
> > there must be written on soem way.
>
> The canonical way to do this is the obvious:
>
>   if person == "George":
> for times in range(0, 5):
>   ...
>
> That said, you can do stupid things to abstract the logic like
>
>   def iterate_if(condition, iterable):
> if condition:
>   for item in iterable:
> yield item
>
> which you can use something like
>
>   for times in iterate_if(person == "George", range(0,5)):
> ...
>
> but I don't advise it.  Mainly, because the iterable will be
> evaluated when passed as an argument, which incurs the runtime cost.
> In the canonical form, if the test isn't passed, the range(n,m) is
> never even evaluated.
>
> -tkc
>
>
> Tim, that's great! or in the wonderful world of Onslow, "Oh nice"
http://en.wikipedia.org/wiki/Onslow_(Keeping_Up_Appearances)


>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread Grant Edwards
On 2013-09-17, Heiko Wundram  wrote:
>
> Am 17.09.2013 01:41, schrieb Steven D'Aprano:
>> I cannot fathom for the life of me a legitimate reason for your
>> website to use a fake IP address and hostname when sending email.
>
> In addition to that: it's amazing that Nikos thinks TCP will still
> work in the presence of spoofed IP addresses. Email without TCP is a
> challenge, at the least.

Somehow I doubt Nikos is up to the task of settup up UUCP and a bank
of dial-up modems.  Even if he could manage it, there probably isn't
anybody to dial-up...

-- 
Grant Edwards   grant.b.edwardsYow! Where's SANDY DUNCAN?
  at   
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: statsmodels.api

2013-09-17 Thread Josef Perktold
Oscar Benjamin  gmail.com> writes:

> 
> On 17 September 2013 14:35, Josef Pktd  gmail.com> wrote:
> >> (As an aside, this is all much simpler if you're using Ubuntu or some
> >> other Linux distro rather than Windows.)
> >
> > scientific python on a stick
> >
> > https://code.google.com/p/winpython/wiki/PackageIndex_33
> 
> Thanks, I've just installed that and I'll try it out later.
> 
> > I haven't seen any problems so far on python 3.3
> > The statsmodels test suite passes without problems on python 3.3 also,
as far as I remember.
> > (and no problems using Windows. just use the right binaries.)
> 
> Well that's exactly my point. On a Linux distro you would have the
> right binaries first time. No need to search through project webpages
> or documentation, weigh up different installers, or download 750MB of
> software that you mostly won't use. Similarly on a Linux distro it's a
> lot easier to get all of the build tools set up to build these things
> from source if you'd prefer.

This might be true for many Linux users.
However, the last time I tried to install something in a virtual Linux OS
that was not in the standard repository, I was completely lost.
(I'm a Windows user.)


> 
> Windows users are often dependent on inconsistent sources of binaries.
> In this case I imagine that the OP installed numpy from sourceforge
> since it has 3.3 binaries but it doesn't have the same for scipy at
> which point googling would easily lead to Cristoph's page.

Another problem with relying on binaries on Windows is when the matching
binaries are not available. For example, the Windows binaries on pypi of
pandas and statsmodels are compiled against the latest numpy release and
will not work with older numpy versions.
(
http://stackoverflow.com/questions/17709641/valueerror-numpy-dtype-has-the-wrong-size-try-recompiling/18369312
)

On the other hand, python-xy comes with MingW, and I never had any problems
compiling pandas and statsmodels for any version combination of python and
numpy that I tested (although 32 bit only so far, I never set up the
Microsoft sdk).

(latest news: moving to MingW-64 for numpy and scipy, and related packages,
might be on the way.)

Josef


> 
> Oscar
> 




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


Re: Python GUI?

2013-09-17 Thread rusi
On Thursday, September 12, 2013 10:21:49 PM UTC+5:30, Benjamin Kaplan wrote:

> The main difference between wx and qt is that qt looks native on every 
> platform 
> while wx *is* native on every platform (it uses native controls wherever 
> possible). This means that wx integrates into the OS better, but your also 
> more 
> likely to need OS-specific tweaks in wx, at least from my experience from a 
> few 
> years ago.

For someone who is GUI-challenged, can you please expand on that a bit?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: statsmodels.api

2013-09-17 Thread Davide Dalmasso
Oscar you are right!

The problem was Numpy!
I re-installed it using an executable that I downloaded from:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy 
I don't remember if previously I installed it using another source.

However the problem now is disappeared!

Many thanks!

Davide

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


Re: Having both if() and for() statements in one liner

2013-09-17 Thread Chris Angelico
On Tue, Sep 17, 2013 at 11:00 PM, Roy Smith  wrote:
> They just discovered a huge newline vein in Montana and they're mining
> the things like crazy.  There's no shortage of them so feel free to use
> as many as you like.  They even get recycled.

Can they keep up with the considerable demand even from Whitespace?

http://en.wikipedia.org/wiki/Whitespace_(programming_language)

I hope the Montanan newlines aren't on silly US export restrictions.
That would be so annoying.

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


Python Developers

2013-09-17 Thread Kelly Lurz
List - I am currently searching for W-2 candidates for several Python Developer 
positions in Mountain View, CA for a high-profile client.  The positions are 
contract-to-perm at a starting rate of $80 an hour.  Below is some additional 
information.  Thank you for sending to your members if you find suitable.

**Requirements**
* 5+ years of experience programming in Python
* 3+ years professional MySQL experience
* Experience in Unix and Linux

**What Python is used for**:
You will be responsible for the design, implementation, testing, and release of 
a centralized data store for metrics related to the software development life 
cycle, with a focus on testing. This data will then be used to automate and aid 
in the analysis of failures, provide reports and trending we can utilize to 
identify areas of improvement, and automate manual processes and release 
decisions. You will interact with other members of the tools team to 
demonstrate designs, integrate with our existing tool chain, and iterate based 
on team feedback. The tool will be used throughout the engineering organization.

**Contact Info:**

* **Contact**: Kelly Lurz - Technical Recruiter
* **E-mail contact**: [email protected]
* **Other Contact Info**: 904-332-7000 ext 110
* **Web**:
* **No telecommuting**


[Description: Description: Meridian_RGB_signature]

Kelly Lurz
Recruiter
5210 Belfort Road, Suite 400
Jacksonville, Florida 32256
O 904 332 7000 ext. 110
C 904 994 0959
F 904 332 0660
[email protected]
www.meridiantechnologies.net
www.meridianstaffing.net
http://www.linkedin.com/pub/kelly-lurz/a/95b/576











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


Re: Having both if() and for() statements in one liner

2013-09-17 Thread Joel Goldstick
On Tue, Sep 17, 2013 at 11:04 AM, Chris Angelico  wrote:

> On Tue, Sep 17, 2013 at 11:00 PM, Roy Smith  wrote:
> > They just discovered a huge newline vein in Montana and they're mining
> > the things like crazy.  There's no shortage of them so feel free to use
> > as many as you like.  They even get recycled.
>
> Can they keep up with the considerable demand even from Whitespace?
>
> http://en.wikipedia.org/wiki/Whitespace_(programming_language)
>
> I hope the Montanan newlines aren't on silly US export restrictions.
> That would be so annoying.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>


You can get them all over the Mediterranean as well!  I think they are like
air --

-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread Ferrous Cranus

On 17/9/2013 1:46 μμ, Heiko Wundram wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Am 17.09.2013 01:41, schrieb Steven D'Aprano:

I cannot fathom for the life of me a legitimate reason for your
website to use a fake IP address and hostname when sending email.


In addition to that: it's amazing that Nikos thinks TCP will still
work in the presence of spoofed IP addresses. Email without TCP is a
challenge, at the least.

- --
- --- Heiko.
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.20 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSODMPAAoJEDMqpHf921/SC0YH/3rCWDcX+rzJKonfeJXUYNxz
nbrBPDsoZf6xPh0socOn88TrzgbZewhWf2l3dHAPOKxTAwUWjRjygatTccBmZur9
6B+t410Nq7axz5+0jg4OwBSOQVt3jr0YInK3vWzq4nd0V0cHchvZzfrdSmnEloDU
V3wIPhBM7MEavyuvrxhutIM8DxA/0z6L/cLhwnpHfE6AxVMeGh/dHhGK9eaxJ03C
pfPWgb2fuCRHrOd3+cLUx3ZFF6YkK00PZzICFhkx236K8iaTvBgqIsod2tpyP6+t
H9qlXCfxit1d6nEzTJavx4suBGStcbhDr1C6VlDaPjfVH+w8842h/0QLhTsMXjY=
=K/XL
-END PGP SIGNATURE-


So cant this be done in python or not?
or is a mtetr of configuring the MTA? conf file?
--
https://mail.python.org/mailman/listinfo/python-list


Re: How do I calculate a mean with python?

2013-09-17 Thread Travis Griggs

On Sep 16, 2013, at 4:33 PM, William Bryant  wrote:

> Hey I am new to python so go easy, but I wanted to know how to make a program 
> that calculates the maen.
> 
> List = [15, 6, 6, 7, 8, 9, 40]
> def mean():
>global themean, thesum
>for i in List:
>thecount = List.count(i)
>thesum = sum(List)
>themean = thesum / thecount
> 
> Why doesn't this work?
> -- 
> https://mail.python.org/mailman/listinfo/python-list

You've had a number of interesting and good responses, some holding your hand 
quite a bit, and others differently.

I think there's a different way to learn what's going wrong, that ISN'T 
mentioned here, and for some people it's a quite effective method of learning. 
I'm a relatively recent import from the Smalltalk community, where this 
approach is more prevalent, I wish it were more so in the Python community.

The way I suggest is to use a debugger. The nice thing about a debugger, is 
that you add a call to mean() at the end, put a breakpoint right there, run, 
and then you can visually walk through what it's doing. This can help find your 
bug, but probably also clarify how Python works in the first place. I use 
pycharm (anyone can use it for free). And there are probably others for free as 
well. 

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


Re: Is this a bug in Python 3.3?

2013-09-17 Thread Terry Reedy

On 9/17/2013 7:22 AM, Aseem Bansal wrote:

While using IDLE I used the license() function to see the license information. 
In it there was a list of all the versions and from which version they are 
derived is written.


The 2.7 list ends with 2.7. The 3.x does not even include 2.7.


The list goes upto 3.3.1 but doesn't include 3.3.2. Is that a minor bug or is 
the current version not mentioned in that list?


I will ask on the python-dev list.

--
Terry Jan Reedy

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


Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-17 Thread stephen . boulet
On Thursday, September 12, 2013 6:01:20 PM UTC-5, [email protected] wrote:
> I have an excel file. When I select cells, copy from excel, and then use 
> win32clipboard to get the contents of the clipboard, I have a 131071 
> character string.
> 
> 
> 
> When I save the file as a text file, and use the python 3.3 open command to 
> read its contents, I only have 80684 characters.
> 
> 
> 
> Excel (and  other programs too) appends a bunch of b'\x00' (or similar) 
> characters.
> 
> 
> 
> Is there a pythonic way to strip these out?

Odd behavior from excel. It seems as though the clipboard contents will vary 
according to the clipboard size. For example, in my 13 column row I select 2023 
rows, copy to the clipboard, and 

def getclipboard():
win32clipboard.OpenClipboard()
s = win32clipboard.GetClipboardData(win32con.CF_TEXT)
win32clipboard.CloseClipboard()
return s

s = getclipboard()

len(s) gives me 16298.

If I select one additional row, len(s) balloons to 32767.

In the first case, s[-10:] is b'0.032573\r\n'.

In the second case, s[-10:] is b'\x008\x008\x000\x005\x00\t'

Does anyone know what is going on with that?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: statsmodels.api

2013-09-17 Thread Josef Perktold
Oscar Benjamin  gmail.com> writes:

> 
> On 17 September 2013 15:52, Josef Perktold  gmail.com> wrote:
> >
> > On the other hand, python-xy comes with MingW, and I never had any problems
> > compiling pandas and statsmodels for any version combination of python and
> > numpy that I tested (although 32 bit only so far, I never set up the
> > Microsoft sdk).
> 
> Just out of interest: out of the box Python.org distutils is
> incompatible with recent versions of MinGW. If Python-xy distributes
> MinGW (and it works) then they're either creating a special patched
> MinGW set up or patching distutils. I don't want to install Python-xy
> myself since it'll clobber my existing Python installation but could
> you answer the following for me:
> 
> 1) What gcc version did Python-xy install for you?
> 
> 2) Does the distutils.cygwincompiler module it installs contain the
> following lines (around about line 300) specifically with the
> '-mno-cygwin' option?
> 
>  self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
>   compiler_so='gcc -mno-cygwin -mdll -O -Wall',
>   compiler_cxx='g++ -mno-cygwin -O -Wall',
>   linker_exe='gcc -mno-cygwin',
>   linker_so='%s -mno-cygwin %s %s'

I installed python-xy 2 years ago with python 2.6 and didn't update, so my
information is not up-to-date

It looks like my MingW version uses mingw32-gcc-4.4.0.exe

for python 2.6 which came with python-xy:
self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
 compiler_so='gcc -mno-cygwin -mdll -O -Wall',
 compiler_cxx='g++ -mno-cygwin -O -Wall',
 linker_exe='gcc -mno-cygwin',
 linker_so='%s -mno-cygwin %s %s'
% (self.linker_dll, shared_option,
   entry_point))

However, I'm running python 2.5, 2.7, 3.2 and 3.3 additionally. And they are
all python.org versions without any changes (except IDLE bugs :).
I don't have any compilation problems with any of them.

Until recently statsmodels used distutils from numpy which adds some patches
AFAIK. The current statsmodels setup.py just uses plain distutils and
setuptools. (The setup.py is largely copied from pandas which has a lot more
C extensions than statsmodels.)

numpy scipy binaries for Windows are still compiled against MingW 3.x, but
David Cournapeau is looking into upgrading to the latest MingW(-64) right now.

also (from some comments about problems a long time ago): I don't have
cygwin installed, so there is no confusion between cygwin and msys/mingw
paths possible. 

Josef

> 
> Oscar
> 




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


Re: statsmodels.api

2013-09-17 Thread Oscar Benjamin
On 17 September 2013 15:52, Josef Perktold  wrote:
>
> On the other hand, python-xy comes with MingW, and I never had any problems
> compiling pandas and statsmodels for any version combination of python and
> numpy that I tested (although 32 bit only so far, I never set up the
> Microsoft sdk).

Just out of interest: out of the box Python.org distutils is
incompatible with recent versions of MinGW. If Python-xy distributes
MinGW (and it works) then they're either creating a special patched
MinGW set up or patching distutils. I don't want to install Python-xy
myself since it'll clobber my existing Python installation but could
you answer the following for me:

1) What gcc version did Python-xy install for you?

2) Does the distutils.cygwincompiler module it installs contain the
following lines (around about line 300) specifically with the
'-mno-cygwin' option?

 self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
  compiler_so='gcc -mno-cygwin -mdll -O -Wall',
  compiler_cxx='g++ -mno-cygwin -O -Wall',
  linker_exe='gcc -mno-cygwin',
  linker_so='%s -mno-cygwin %s %s'


Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weird ttk behaviour

2013-09-17 Thread Rotwang

On 17/09/2013 15:35, Chris Angelico wrote:

On Wed, Sep 18, 2013 at 12:25 AM, Rotwang  wrote:

In fact, if I replace tkderp with this:


# begin tkderp.py

import tkinter as tk

_root = tk.Tk()
_root.withdraw()

# end tkderp.py


then simply importing tkderp before tkderp2 is enough to make the latter
work properly


Nice piece of detective work! Alas, I don't know tkinter well enough
to help with the details, but this is exactly what I'd like to hear if
I were trying to pick this up and debug it :)


I don't know tkinter well enough either, but the fact that it behaves 
differently on Linux and Windows suggests to me that at least one 
version is bugging out. Do you think this is worth raising on 
bugs.python.org?




Tkinter experts, anywhere? Where's Ranting Rick when you need him...


Last time I saw him was in this thread:

https://mail.python.org/pipermail/python-list/2013-June/650257.html
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python GUI?

2013-09-17 Thread Benjamin Kaplan
On Tue, Sep 17, 2013 at 7:55 AM, rusi  wrote:
> On Thursday, September 12, 2013 10:21:49 PM UTC+5:30, Benjamin Kaplan wrote:
>
>> The main difference between wx and qt is that qt looks native on every 
>> platform
>> while wx *is* native on every platform (it uses native controls wherever
>> possible). This means that wx integrates into the OS better, but your also 
>> more
>> likely to need OS-specific tweaks in wx, at least from my experience from a 
>> few
>> years ago.
>
> For someone who is GUI-challenged, can you please expand on that a bit?
> --

Sure. Every platform provides its own GUI library (Cocoa on Mac OS X,
Win32 on Windows). Other programs that want to hook into yours, such
as screen readers, are familiar with the platform's native GUI
elements- it knows what a Win32 combo box is, and it knows how to read
the text inside it.

The other way to make a GUI is to take a blank canvas and draw on it
yourself. This is more flexible and provides a more consistent
experience across platforms, but unless you specifically go out of
your way to provide hooks for other programs to jump in, all they see
is a bunch of pixels on the screen. In addition, drawing your own
stuff won't necessarily give you the "normal for the operating system"
behavior on other things, like tab behavior. It's possible for
non-native GUI environments to mimic this behavior (and QT does a
pretty good job of this), but there's always going to be little things
that seem a bit off.

The situation is a bit more complicated because QT is the native
toolkit on KDE, so in that environment, QT will be more "correct" than
wx, which would be using GTK if present and plain X11 if it isn't.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weird ttk behaviour

2013-09-17 Thread Chris Angelico
On Wed, Sep 18, 2013 at 2:11 AM, Rotwang  wrote:
> I don't know tkinter well enough either, but the fact that it behaves
> differently on Linux and Windows suggests to me that at least one version is
> bugging out. Do you think this is worth raising on bugs.python.org?

Possibly, but I'd keep it here on python-list for the moment; it may
be you're actually using undefined behaviour somewhere, in which case
the solution is to change your code. Once someone else (someone who
actually knows what he's talking about, for preference) can confirm
what's going on, it'll be bug report time, I think.

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


Re: Python GUI?

2013-09-17 Thread rusi
On Tuesday, September 17, 2013 9:49:28 PM UTC+5:30, Benjamin Kaplan wrote:
> On Tue, Sep 17, 2013 at 7:55 AM, rusi  wrote:
> 
> > On Thursday, September 12, 2013 10:21:49 PM UTC+5:30, Benjamin Kaplan wrote:
> 
> >
> >> The main difference between wx and qt is that qt looks native on every 
> >> platform
> >> while wx *is* native on every platform (it uses native controls wherever
> >> possible). This means that wx integrates into the OS better, but your also 
> >> more
> >> likely to need OS-specific tweaks in wx, at least from my experience from 
> >> a few
> >> years ago.
> >
> > For someone who is GUI-challenged, can you please expand on that a bit?
> > --
> 
> Sure. Every platform provides its own GUI library (Cocoa on Mac OS X,
> Win32 on Windows). Other programs that want to hook into yours, such
> as screen readers, are familiar with the platform's native GUI
> elements- it knows what a Win32 combo box is, and it knows how to read
> the text inside it.
> 
> 
> The other way to make a GUI is to take a blank canvas and draw on it
> yourself. This is more flexible and provides a more consistent
> experience across platforms, but unless you specifically go out of
> your way to provide hooks for other programs to jump in, all they see
> is a bunch of pixels on the screen. In addition, drawing your own
> stuff won't necessarily give you the "normal for the operating system"
> behavior on other things, like tab behavior. It's possible for
> non-native GUI environments to mimic this behavior (and QT does a
> pretty good job of this), but there's always going to be little things
> that seem a bit off.

Thanks for the explanation. However I am not able to square it up:

You seem to be saying that QT draws on a blank canvas rather than calling out 
to the OS library.
You also seem to be saying that QT (for the most part) Does the Right Thing for 
each platform.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread Denis McMahon
On Tue, 17 Sep 2013 18:17:43 +0300, Ferrous Cranus wrote:

> So cant this be done in python or not?
> or is a mtetr of configuring the MTA? conf file?

Python can not control data that is added to the message after it has 
left the python program. If you want to retain maximum possible control 
of the mail process from within python, you need to use a python module 
that handles the smtp exchange with the destination mta, however even 
then you can not control the content of header lines added by that 
destination mta, which will invariably include the real[1] ip address of 
your system.

[1] The ip address that it is sending ack packets to as part of the smtp 
session, so unless you're using a proxy somewhere, this will be your 
system's ip address. Can't fake it. If the other system doesn't know your 
ip address, it can't send acks, and the tcp session fails.

-- 
Denis McMahon, [email protected]
-- 
https://mail.python.org/mailman/listinfo/python-list


Suds and Complex Sequences

2013-09-17 Thread Greg Lindstrom
Hello Everyone -

I am trying to use Suds, the very fine library allowing me to use SOAP, to
query a service over the net.  Part of the data structure defined be the
WSDL calls for a sequence of SubscriberDataTypes (this application is used
to test an insurance companys' rating service).

(SubscriberDataType){
   SubscriberID = None
   SubscriberBirthDate = None
   Zip = None
   
   DependentData[] = 
 }

Which goes into

(MedicalRatingRequest){
   MessageHeader =
  (MessageHeaderType){
 MessageName = None
 MessageID = None
 
  }
   RequestHeader =
  (RequestHeaderType){
 RequestType =
(RequestTypeEnum){
   value = None
}
 
  }
   
   SubscriberData[] = 
 }

Note that the Subscriber Data is a sequence of SubscriberDataType.  I have
not been able to find any documentation showing me how to do this.  Does
anyone out there know how I can generate the request?

Thanks for your time,

Greg Lindstrom
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python GUI?

2013-09-17 Thread Benjamin Kaplan
On Tue, Sep 17, 2013 at 9:51 AM, rusi  wrote:
> On Tuesday, September 17, 2013 9:49:28 PM UTC+5:30, Benjamin Kaplan wrote:
>> On Tue, Sep 17, 2013 at 7:55 AM, rusi  wrote:
>>
>> > On Thursday, September 12, 2013 10:21:49 PM UTC+5:30, Benjamin Kaplan 
>> > wrote:
>>
>> >
>> >> The main difference between wx and qt is that qt looks native on every 
>> >> platform
>> >> while wx *is* native on every platform (it uses native controls wherever
>> >> possible). This means that wx integrates into the OS better, but your 
>> >> also more
>> >> likely to need OS-specific tweaks in wx, at least from my experience from 
>> >> a few
>> >> years ago.
>> >
>> > For someone who is GUI-challenged, can you please expand on that a bit?
>> > --
>>
>> Sure. Every platform provides its own GUI library (Cocoa on Mac OS X,
>> Win32 on Windows). Other programs that want to hook into yours, such
>> as screen readers, are familiar with the platform's native GUI
>> elements- it knows what a Win32 combo box is, and it knows how to read
>> the text inside it.
>>
>>
>> The other way to make a GUI is to take a blank canvas and draw on it
>> yourself. This is more flexible and provides a more consistent
>> experience across platforms, but unless you specifically go out of
>> your way to provide hooks for other programs to jump in, all they see
>> is a bunch of pixels on the screen. In addition, drawing your own
>> stuff won't necessarily give you the "normal for the operating system"
>> behavior on other things, like tab behavior. It's possible for
>> non-native GUI environments to mimic this behavior (and QT does a
>> pretty good job of this), but there's always going to be little things
>> that seem a bit off.
>
> Thanks for the explanation. However I am not able to square it up:
>
> You seem to be saying that QT draws on a blank canvas rather than calling out 
> to the OS library.
> You also seem to be saying that QT (for the most part) Does the Right Thing 
> for each platform.
> --

Right. The QT developers have been working for years to get their
controls to quack like the native ones, even though they aren't
native. They started from controls that looked and worked the same on
all platforms and have been trying to get them to play nicely with the
environment they're running in. wx has been working from the opposite
direction- they started with wrapping the native API and have been
working on getting their API to make programs come out the same even
when using different underlying toolkits. When I used wx about 5 years
ago, some of the layout got messed up when we first ran the program
(developed on Linux/GTK+)  on a Mac because of some differences
between how Carbon and GTK+ draw their controls.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Having both if() and for() statements in one liner

2013-09-17 Thread Dave Angel
On 17/9/2013 09:21, Ferrous Cranus wrote:


> I just want to say tot he program that
>
> that only run the for statement if and only if person=='George'
>
> I dont see nay reason as to why this fails
>
> perhaps like:
>
> for times in range(0, 5) if person=='George':
>
> but that fails too...
> there must be written on soem way.
>
>

untested:

for times in range(0, 5 if person=="George" else 0):

But i also greately prefer the canonical version.

-- 
DaveA


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


Re: Suds and Complex Sequences

2013-09-17 Thread John Gordon
In  Greg Lindstrom 
 writes:

> --089e0122976c27f48b04e697f887
> Content-Type: text/plain; charset=ISO-8859-1

> Hello Everyone -

> I am trying to use Suds, the very fine library allowing me to use SOAP, to
> query a service over the net.  Part of the data structure defined be the
> WSDL calls for a sequence of SubscriberDataTypes (this application is used
> to test an insurance companys' rating service).

Contact whomever is providing this data and ask them for documentation.

-- 
John Gordon   A is for Amy, who fell down the stairs
[email protected]  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: How do I calculate a mean with python?

2013-09-17 Thread William Bryant
'''#*'''
#* Name:Mode-Median-Mean Calculator   *#
#**#
#* Purpose: To calculate the mode, median and mean of a list of numbers   *#
#*  and the mode of a list of strings because that is what we are *#
#*  learning in math atm in school :P *#
#**#
#* Author:  William Bryant*#
#**#
#* Created: 11/09/2013*#
#**#
#* Copyright:   (c) William 2013  *#
#**#
#* Licence: IDK :3*#
'''**'''



#-#   ~~Import things I am using~~   #-#

# |
#|
#   \/

import time
import itertools



#-#~~Variables that I am using, including the list.~~#-#

# |
#|
#   \/

List = []
NumberOfXItems = []
themode = None
themean = None
count = None

#-#   ~~Functions that I am using.~~ #-#

# |
#|
#   \/

def HMNs():
global TheStr, user_inputHMNs, List_input, List
user_inputHMNs = input("You picked string. This program cannot calculate 
the mean or median, but it can calculate the mode. :D  How many strings are you 
using in your list? (Can not be a decimal number)  \nEnter:  ")
user_inputHMNs
time.sleep(1.5)
TheStr = int(user_inputHMNs)
for i in range(TheStr):
List_input = input("Enter your strings. (One in each input field):  ")
List.append(List_input)
print("Your list -> ", List)
if List.count == int(user_inputHMNs):
break
mode()
mean()
print("\n*Mode*:", themode)
print("*Median*:",  "\n")
print("*Mean*:",themean)

def HMNn():
global TheNum, user_inputHMNn, List_input, List
user_inputHMNn = input("You picked number. :D How many numbers are you 
using in your list? (Can not be a decimal number) \nEnter:  ")
user_inputHMNn
time.sleep(1.5)
TheNum = int(user_inputHMNn)
for i in range(TheNum):
List_input = input("Enter your numbers. (One in each input field):  ")
List_input = int(List_input)
List.append(List_input)
print("\nYour list -> ", List)
if List.count == int(user_inputHMNn):
break
mode()
mean()
print("\n*Mode*:", themode)
print("*Median*:",  "")
print("*Mean*:",themean)

def NOS():
while True: # Loops forever (until the break)
answer = input("Does your list contain a number or a string?  \nEnter: 
")
answer = answer.lower()
if answer in ("string", "str", "s"):
HMNs()
break
elif answer in ("number", "num", "n", "int"):
HMNn()
break
elif answer in ("quit", "q"):
break  # Exits the while loop
else:
print("You did not enter a valid field, :P Sorry.  \nEnter: ")
time.sleep(1.5)

def mean():
global themean
thecount = []
for i in List:
thecount.append(List.count(i))
thesum = sum(List)
thecount = sum(thecount)
themean = thesum / thecount

def mode():
global themode
max_occurrences = 0
themode = None
for i in List:
thecount = List.count(i)
if thecount > max_occurrences:
max_occurrences = thecount
themode = i



#-#   ~~The functions which need calling~~   #-#

# |
#|
#   \/

NOS()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I calculate a mean with python?

2013-09-17 Thread William Bryant
Ok I think I've fixed it thanks I read everything.

'''**'''
#* Name:Mode-Median-Mean Calculator   *#
#**#
#* Purpose: To calculate the mode, median and mean of a list of numbers   *#
#*  and the mode of a list of strings because that is what we are *#
#*  learning in math atm in school :P *#
#**#
#* Author:  William Bryant*#
#**#
#* Created: 11/09/2013*#
#**#
#* Copyright:   (c) William 2013  *#
#**#
#* Licence: IDK :3*#
'''**'''



#-#   ~~Import things I am using~~   #-#

# |
#|
#   \/

import time
import itertools



#-#~~Variables that I am using, including the list.~~#-#

# |
#|
#   \/

List = []
NumberOfXItems = []

#-#   ~~Functions that I am using.~~ #-#

# |
#|
#   \/

def HMNs():
global TheStr, user_inputHMNs, List_input, List
user_inputHMNs = input("You picked string. This program cannot calculate 
the mean or median, but it can calculate the mode. :D  How many strings are you 
using in your list? (Can not be a decimal number)  \nEnter:  ")
user_inputHMNs
time.sleep(1.5)
TheStr = int(user_inputHMNs)
for i in range(TheStr):
List_input = input("Enter your strings. (One in each input field):  ")
List.append(List_input)
print("Your list -> ", List)
if List.count == int(user_inputHMNs):
break
print("\n*Mode*:", mode())
print("*Median*:",  "\n")
print("*Mean*:",mean())

def HMNn():
global TheNum, user_inputHMNn, List_input, List
user_inputHMNn = input("You picked number. :D How many numbers are you 
using in your list? (Can not be a decimal number) \nEnter:  ")
user_inputHMNn
time.sleep(1.5)
TheNum = int(user_inputHMNn)
for i in range(TheNum):
List_input = input("Enter your numbers. (One in each input field):  ")
List_input = int(List_input)
List.append(List_input)
print("\nYour list -> ", List)
if List.count == int(user_inputHMNn):
break
print("\n*Mode*:", mode())
print("*Median*:",  "")
print("*Mean*:",mean())

def NOS():
while True: # Loops forever (until the break)
answer = input("Does your list contain a number or a string?  \nEnter: 
")
answer = answer.lower()
if answer in ("string", "str", "s"):
HMNs()
break
elif answer in ("number", "num", "n", "int"):
HMNn()
break
elif answer in ("quit", "q"):
break  # Exits the while loop
else:
print("You did not enter a valid field, :P Sorry.  \nEnter: ")
time.sleep(1.5)

def mean():
thesum = sum(List)
amount = len(List)
themean = thesum / amount
return themean

def mode():
max_occurrences = 0
themode = None
for i in List:
thecount = List.count(i)
if thecount > max_occurrences:
max_occurrences = thecount
themode = i
return themode



#-#   ~~The functions which need calling~~   #-#

# |
#|
#   \/

NOS()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I calculate a mean with python?

2013-09-17 Thread William Bryant
Sorry guys, I didn't read anything u said. Because I just figured it out on my 
own :)
I'll read it now. But u can check out my program I have done so far (It works 
but I think it needs some tidying up.) :)

Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I calculate a mean with python?

2013-09-17 Thread Joel Goldstick
On Tue, Sep 17, 2013 at 4:10 PM, William Bryant  wrote:

> Ok I think I've fixed it thanks I read everything.
>
>
> '''**'''
> #* Name:Mode-Median-Mean Calculator
> *#
> #*
>*#
> #* Purpose: To calculate the mode, median and mean of a list of
> numbers   *#
> #*  and the mode of a list of strings because that is what we
> are *#
> #*  learning in math atm in school :P
> *#
> #*
>*#
> #* Author:  William Bryant
>*#
> #*
>*#
> #* Created: 11/09/2013
>*#
> #*
>*#
> #* Copyright:   (c) William 2013
>*#
> #*
>*#
> #* Licence: IDK :3
>*#
>
> '''**'''
>
> The above comments are a mess.  In python, use docstrings -- put 3 quotes
> in front of all the documentation, and 3 at the end like:
> """
>
Name:Mode-Median-Mean Calculator
Purpose: To calculate the mode, median and mean of a list of
numbers   *#
"""

There is a utility called pydoc that will pull all docstrings from a module
and produce nice documentation.  So better to learn this style early

#-#   ~~Import things I am using~~
#-#

# |
#|
#   \/

import time
import itertools

I don't think you use itertools, so remove the reference

#-#~~Variables that I am using, including the list.~~
 #-#

# |
#|
#   \/

List = []
NumberOfXItems = []

Using global variables is a very bad idea.  Since you seem to be a novice,
I'm wondering where you even learned about global variables.  If your
instructor taught you, then (s)he should look for a new line of work.
Using globals promotes lazy thought, makes debugging impossible in any
reasonably large piece of code.  Google about that.  Its important


#-#   ~~Functions that I am using.~~
> #-#
>
> # |
> #|
> #   \/
>
> Use better names.  What does HMNs mean?  This function asks the user to
input a list of strings or numbers.  It is almost identical to HMNn to that
point that they should be combined most likely.


> def HMNs():
>
  """
  Here you should write about the function -- what it does, what is
needs passed to it, and what it returns.
  """




> global TheStr, user_inputHMNs, List_input, List
> user_inputHMNs = input("You picked string. This program cannot
> calculate the mean or median, but it can calculate the mode. :D  How many
> strings are you using in your list? (Can not be a decimal number)  \nEnter:
>  ")
> user_inputHMNs
> time.sleep(1.5)
> TheStr = int(user_inputHMNs)
> for i in range(TheStr):
> List_input = input("Enter your strings. (One in each input field):
>  ")
> List.append(List_input)
> print("Your list -> ", List)
> if List.count == int(user_inputHMNs):
> break
> print("\n*Mode*:", mode())
> print("*Median*:",  "\n")
> print("*Mean*:",mean())
>
> def HMNn():
> global TheNum, user_inputHMNn, List_input, List
> user_inputHMNn = input("You picked number. :D How many numbers are you
> using in your list? (Can not be a decimal number) \nEnter:  ")
> user_inputHMNn
> time.sleep(1.5)
> TheNum = int(user_inputHMNn)
> for i in range(TheNum):
> List_input = input("Enter your numbers. (One in each input field):
>  ")
> List_input = int(List_input)
> List.append(List_input)
> print("\nYour list -> ", List)
> if List.count == int(user_inputHMNn):
> break
> print("\n*Mode*:", mode())
> print("*Median*:",  "")
> print("*Mean*:",mean())
>
> def NOS():
> while True: # Loops forever (until the break)
> answer = input("Does your list contain a number or a string?
>  \nEnter: ")
> answer = answer.lower()
> if answer in ("string", "str", "s"):
> HMNs()
> break
> elif answer in ("number", "num", "n", "int"):
> HMNn()
> break
> elif answer in ("quit", "q"):
> break  # Exits the while loop
> else:
> print("You did not enter a valid field, :P Sorry.  \nEnter: ")
> time.sleep(1.5)
>
> def mean():
> thesum = sum(List)
> amount = len(List)
> themean = thesum / amount
> return themean
>
> def mode():
> max_occurrences = 0
> themode = None
> for i in List:
> thecount = List.count(i)
> if thecount > max_occurrences:
> max_occurrences = thecount
> themode = i
> return themode
>
>
>
> #-#   ~~The functions which need calling~~
> #-#
>
> # |
> #|
> #   \/
>
> NOS()
>


So, I just added a few criticisms earlier above.  To sumarize:
   avoid global variables, document functions with docstrings, use really
clear na

Re: How do I calculate a mean with python?

2013-09-17 Thread MRAB

On 17/09/2013 21:10, William Bryant wrote:

Ok I think I've fixed it thanks I read everything.


[snip]


def HMNs():
 global TheStr, user_inputHMNs, List_input, List
 user_inputHMNs = input("You picked string. This program cannot calculate the 
mean or median, but it can calculate the mode. :D  How many strings are you using in your 
list? (Can not be a decimal number)  \nEnter:  ")


This line doesn't do anything:


 user_inputHMNs
 time.sleep(1.5)
 TheStr = int(user_inputHMNs)
 for i in range(TheStr):
 List_input = input("Enter your strings. (One in each input field):  ")
 List.append(List_input)
 print("Your list -> ", List)


List.count is a method; it will never equal an integer:


 if List.count == int(user_inputHMNs):
 break
 print("\n*Mode*:", mode())
 print("*Median*:",  "\n")
 print("*Mean*:",mean())

def HMNn():
 global TheNum, user_inputHMNn, List_input, List
 user_inputHMNn = input("You picked number. :D How many numbers are you using in 
your list? (Can not be a decimal number) \nEnter:  ")


This line doesn't do anything:


 user_inputHMNn
 time.sleep(1.5)
 TheNum = int(user_inputHMNn)
 for i in range(TheNum):
 List_input = input("Enter your numbers. (One in each input field):  ")
 List_input = int(List_input)
 List.append(List_input)
 print("\nYour list -> ", List)


List.count is a method; it will never equal an integer:


 if List.count == int(user_inputHMNn):
 break
 print("\n*Mode*:", mode())
 print("*Median*:",  "")
 print("*Mean*:",mean())


[snip]

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


BDD behave support for vim

2013-09-17 Thread Matěj Cepl
Hi,

I know that vim has native support for cucumber (the original BDD 
framework for Ruby). I have also found 
https://github.com/veloce/vim-behat for BDD with PHP (frightening 
idea!), but I haven't found a module supporting BDD with vim and Python.  
Especially I envy to our Ruby friends ability to jump from the 
particular line in the .feature file to the definition of step in the 
appropriate Ruby file.

Does anybody know about any project which would do the same with behave 
what vim does for Ruby?

Thank you,

Matěj
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I calculate a mean with python?

2013-09-17 Thread William Bryant
Thanks to all and @Joel Goldstick, I am learning python through youtube. They 
explained Global and Local variables to me. :) Thanks for that critisism, it 
really helps. I am 13 years old and I am looking forward to studing programming 
in University! :DD

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


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread Chris Angelico
On Wed, Sep 18, 2013 at 7:42 AM, Ferrous Cranus  wrote:
> So the foreign MTA tests for real time connectivity with the local MTA and
> it tries to detect a working host and ip address.

No, the local MTA connects to the foreign MTA.

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


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread Ferrous Cranus

On 17/9/2013 7:30 μμ, Denis McMahon wrote:

On Tue, 17 Sep 2013 18:17:43 +0300, Ferrous Cranus wrote:


So cant this be done in python or not?
or is a mtetr of configuring the MTA? conf file?


Python can not control data that is added to the message after it has
left the python program. If you want to retain maximum possible control
of the mail process from within python, you need to use a python module
that handles the smtp exchange with the destination mta, however even
then you can not control the content of header lines added by that
destination mta, which will invariably include the real[1] ip address of
your system.

[1] The ip address that it is sending ack packets to as part of the smtp
session, so unless you're using a proxy somewhere, this will be your
system's ip address. Can't fake it. If the other system doesn't know your
ip address, it can't send acks, and the tcp session fails.


Ah, now we are getting somewhere.

So the foreign MTA tests for real time connectivity with the local MTA 
and it tries to detect a working host and ip address.


So even if we alter the hostname and the ip address of our localhost 
then the smtp procedure will fail correct?

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


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread William Ray Wing
On Sep 17, 2013, at 5:42 PM, Ferrous Cranus  wrote:

> On 17/9/2013 7:30 μμ, Denis McMahon wrote:
>> On Tue, 17 Sep 2013 18:17:43 +0300, Ferrous Cranus wrote:
>> 
>>> So cant this be done in python or not?
>>> or is a mtetr of configuring the MTA? conf file?
>> 
>> Python can not control data that is added to the message after it has
>> left the python program. If you want to retain maximum possible control
>> of the mail process from within python, you need to use a python module
>> that handles the smtp exchange with the destination mta, however even
>> then you can not control the content of header lines added by that
>> destination mta, which will invariably include the real[1] ip address of
>> your system.
>> 
>> [1] The ip address that it is sending ack packets to as part of the smtp
>> session, so unless you're using a proxy somewhere, this will be your
>> system's ip address. Can't fake it. If the other system doesn't know your
>> ip address, it can't send acks, and the tcp session fails.
>> 
> Ah, now we are getting somewhere.
> 
> So the foreign MTA tests for real time connectivity with the local MTA and it 
> tries to detect a working host and ip address.
> 
> So even if we alter the hostname and the ip address of our localhost then the 
> smtp procedure will fail correct?
> -- 
> https://mail.python.org/mailman/listinfo/python-list

I think you need to read up on some of the most basic fundamentals of tcp/ip 
networking, i.e., the basis of the global internet.  EVERY network packet (and 
I do mean every) packet in an IP network carries both a source and a 
destination address in its header.  These are fundamentally necessary in order 
to allow the gateway router at the originating site to direct an outgoing 
packet to its destination, and allow the receiving host at the destination site 
to craft reply packets.

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


Re: How do I calculate a mean with python?

2013-09-17 Thread Joel Goldstick
On Tue, Sep 17, 2013 at 5:31 PM, William Bryant  wrote:

> Thanks to all and @Joel Goldstick, I am learning python through youtube.
> They explained Global and Local variables to me. :) Thanks for that
> critisism, it really helps. I am 13 years old and I am looking forward to
> studing programming in University! :DD
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Well, learn away.  Try the python.org tutorial too.  The best way to learn
( I think!) is to find all the tutorials you can and work through those
that suit you.  Look at python.org for pages that list many help sites,
including those for beginners.  Also, there is a python-tutor mailing
list/newsgroup that may be better for you at your stage of learning.  Keep
coming back when you get stuck

-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: statsmodels.api

2013-09-17 Thread Josef Perktold
Josef Perktold  gmail.com> writes:

> 
> Oscar Benjamin  gmail.com> writes:
> 
> > 
> > On 17 September 2013 15:52, Josef Perktold  gmail.com>
wrote:
> > >
> > > On the other hand, python-xy comes with MingW, and I never had any
problems
> > > compiling pandas and statsmodels for any version combination of python and
> > > numpy that I tested (although 32 bit only so far, I never set up the
> > > Microsoft sdk).
> > 
> > Just out of interest: out of the box Python.org distutils is
> > incompatible with recent versions of MinGW. If Python-xy distributes
> > MinGW (and it works) then they're either creating a special patched
> > MinGW set up or patching distutils. I don't want to install Python-xy
> > myself since it'll clobber my existing Python installation but could
> > you answer the following for me:
> > 
> > 1) What gcc version did Python-xy install for you?

I did a bit of homework. I didn't know about the -mno-cygwin issue since it
didn't affect me yet.

python-xy is staying below 4.6: GCC Core, G77, G++ 4.5.2 ; MingW 4.5.2.3 
https://code.google.com/p/pythonxy/wiki/StandardPlugins
and has open issue on it

pandas has an open issue where a user reported problems with --mno-cygwin.

Josef


> 
> Josef
> 
> > 
> > Oscar
> > 
> 
> 




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


scipy 11 and scipy 12

2013-09-17 Thread Susan Lubbers
Our group is a python 2.7 which is installed in a shared area.  We  
have scipy 11 installed in site-packages.  How would I install scipy  
12 so that I used the shared install of python but scipy 12 instead of  
11?

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


Simple security between prototype iPhone app and SimpleHTTPServer REST service?

2013-09-17 Thread Travis Griggs
I'm prototyping a simple data collection service. I've implemented a simple 
REST API implemented with python 3x stock HTTPServer. And a simple iPhone app 
that submits data via a json/POST. And it all works just great when my iPhone 
is on the same network as the server.

But now I want to go the next step. I don't need to move beyond prototype/PoC 
yet, I just want to be able to do it outside of our internal network. Issues 
aside of getting access, name resolution, a port and that kind of stuff... what 
kind of security should I add to it? I might as well be a complete neophyte in 
this area. I've read a number of posts and such, and I get some of the pieces, 
at some level, but any confidence how to put that part of a web stack together 
elude me.

I found a example of how to add SSL to my python service 
(https://gist.github.com/ubershmekel/6194556). If I can figure out how to get 
the right keys embedded into my iPhone app (it's just on my phone, not anyone 
else's), is that enough? Or should I include some sort of auth? If so, what 
kind? And any pointers to how to start that would be much appreciated.

Some have blithely replied that I should be using Flask or Tornado. I get that 
I'm going to hit a wall with HTTPServer and that it's more of a "toy" 
implementation. But I don't want to get buried in learning a big framework 
either. If it was relatively easy to convert my simple REST service to one 
running on Tornado or Flask, without loading a bunch of other frameworks, and I 
got easy access to security services and good examples how to do them, that'd 
be fine with me. So far, my searches haven't turned up the simple recipe of 
"so, you've made a simple REST API with HttpServer, here's how to take it to 
the semi secure public level using a real web framework."

Travis Griggs
-- I multiple all estimates by pi to account from running around in circles.
-- 
https://mail.python.org/mailman/listinfo/python-list


*.csv to *.txt after adding columns

2013-09-17 Thread Bryan Britten
Hey, gang, I've got a problem here that I'm sure a handful of you will know how 
to solve. I've got about 6 *.csv files that I am trying to open; change the 
header names (to get rid of spaces); add two new columns, which are just the 
results of a string.split() command; drop the column I just split; and then 
finally export to *.txt files. Here's the code I'm using:

import os
import csv


fileHandle = 'Path/To/Data'
varNames = 
'ID\tCaseNum\tDate\tTime\tBlock\tIUCR\tPrimaryType\tDescription\tLocDesc\tArrest\tDomestic\tBeat\tDistrict\tWard\tCommArea\tFBICode\tXCoord\tYCoord\tYear\tUpdatedOn\tLat\tLong\tLoc\n'

for csvFile in os.listdir(fileHandle):
outFile = open(fileHandle + os.path.splitext(csvFile)[0] + '.txt', 'w')
inFile = open(fileHandle + csvFile, 'rb')
reader = csv.reader(inFile, delimiter=',')
rowNum = 0
for row in reader:
if rowNum == 0:
outFile.write(varNames)
rowNum += 1
else:
date, time = row[2].split()
row.insert(3, date)
row.insert(4, time)
row.remove(row[2])
outFile.write('\t'.join(row) + '\n')
outFile.close()
inFile.close()  


The issue I'm having is that the *.txt files I'm generating are empty. I assume 
some unraised error is being thrown, but I'm new to Python and am self taught, 
so I don't know where to look or how to troubleshoot.

When I run the code on just one file and print the output instead of writing 
it, it looks exactly like what I'd want. So I'm at a loss for where the problem 
is.

Any help is appreciated!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I calculate a mean with python?

2013-09-17 Thread Bryan Britten
William -

I'm also self-teaching myself Python and get stuck quite often, so I understand 
both the thrill of programming and the frustration. Given your young age and 
presumably very little exposure to other programming languages, I would highly 
recommend you check out http://www.Codecademy.com and work through their Python 
tutorials. It will teach you about the different object types (lists, dicts, 
tuples, etc) and about things like functions, methods and classes. I think 
you'll have a MUCH better understanding of Python that will allow you to choose 
which YouTube videos to watch much more wisely.

Good luck with your endeavors!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Having both if() and for() statements in one liner

2013-09-17 Thread Steven D'Aprano
On Tue, 17 Sep 2013 18:54:51 +, Dave Angel wrote:

> for times in range(0, 5 if person=="George" else 0):


Oh that is evil. Truly evil.

Thank you, I will treasure that piece of code forever.


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


Re: *.csv to *.txt after adding columns

2013-09-17 Thread Dave Angel
On 17/9/2013 21:42, Bryan Britten wrote:

> Hey, gang, I've got a problem here that I'm sure a handful of you will know 
> how to solve. I've got about 6 *.csv files that I am trying to open; change 
> the header names (to get rid of spaces); add two new columns, which are just 
> the results of a string.split() command; drop the column I just split; and 
> then finally export to *.txt files. Here's the code I'm using:
>
> import os
> import csv
>
>
> fileHandle = 'Path/To/Data'
> varNames = 
> 'ID\tCaseNum\tDate\tTime\tBlock\tIUCR\tPrimaryType\tDescription\tLocDesc\tArrest\tDomestic\tBeat\tDistrict\tWard\tCommArea\tFBICode\tXCoord\tYCoord\tYear\tUpdatedOn\tLat\tLong\tLoc\n'
>
> for csvFile in os.listdir(fileHandle):
> outFile = open(fileHandle + os.path.splitext(csvFile)[0] + '.txt', 'w')
> inFile = open(fileHandle + csvFile, 'rb')
> reader = csv.reader(inFile, delimiter=',')
> rowNum = 0
> for row in reader:
> if rowNum == 0:
> outFile.write(varNames)
> rowNum += 1
> else:
> date, time = row[2].split()
> row.insert(3, date)
> row.insert(4, time)
> row.remove(row[2])
> outFile.write('\t'.join(row) + '\n')
> outFile.close()
> inFile.close()  
>
>
> The issue I'm having is that the *.txt files I'm generating are empty. I 
> assume some unraised error is being thrown, 

How can you NOT know if an exception is being raised?  How are you
running the code, in a terminal window?  Can't you just see what gets
printed (as stderr)?


> but I'm new to Python and am self taught, so I don't know where to look
> or how to troubleshoot.
>
> When I run the code on just one file and print the output instead of writing 
> it, it looks exactly like what I'd want. So I'm at a loss for where the 
> problem is.

You describe two changes, but don't show them.  How about you do them
one at a time, or perhaps even better, add prints so it both does the
file(s) AND prints the output?

What I think is happening is that you're missing the path separator
between the "Path/To/Data" and the basename.  You should be combining
those with os.path.join(), not with +

For a quick & dirty check, add a trailing slash to the fileHandle. But
that's not the right way to fix it.


-- 
DaveA


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


Re: *.csv to *.txt after adding columns

2013-09-17 Thread Bryan Britten
Dave -

I can't print the output because there are close to 1,000,000 records. It would 
be extremely inefficient and resource intensive to look at every row. Like I 
said, when I take just one file and run the code over the first few records I 
get what I'd expect to see. Here's an example(non-redacted code):

INPUT:

import csv

fileHandle = 'C:/Users/Bryan/Data Analysis/Crime Analysis/Data/'

varNames = 
'ID\tCaseNum\tDate\tTime\tBlock\tIUCR\tPrimaryType\tDescription\tLocDesc\tArrest\tDomestic\tBeat\tDistrict\tWard\tCommArea\tFBICode\tXCoord\tYCoord\tYear\tUpdatedOn\tLat\tLong\tLoc\n'

outFile = open(fileHandle + 'ChiCrime01_02.txt', 'w')
inFile = open(fileHandle + 'ChiCrime01_02.csv', 'rb')
reader = csv.reader(inFile, delimiter=',')
rowNum = 0
for row in reader:
if rowNum < 5:
if rowNum >= 1:
date, time = row[2].split()
row.insert(3, date)
row.insert(4, time)
row.remove(row[2])
print '\t'.join(row)
rowNum+=1
else:
print varNames
rowNum+=1


OUTPUT:

ID  CaseNum DateTimeBlock   IUCRPrimaryType Description 
LocDesc Arrest  DomesticBeatDistrictWardCommArea
FBICode XCoord  YCoord  YearUpdatedOn   Lat LongLoc

2924745 HJ60260212/31/2002  23:59   006XX W 117TH ST841 
THEFT   FINANCIAL ID THEFT:$300 &UNDER  RESIDENCE PORCH/HALLWAY FALSE   FALSE   
524 5   34  53  6   1173831 1827387 20023/30/2006 21:10 
41.68175482 -87.63931351(41.681754819160666, -87.63931350564216)

2523290 HJ10109112/31/2002  23:59   002XX W 112TH PL1310
CRIMINAL DAMAGE TO PROPERTY APARTMENT   FALSE   FALSE   522 
34  49  14  1176848 1830383 20023/30/2006 21:10 41.68990907 
-87.62817988(41.689909072449474, -87.62817987594765)

2527332 HJ10513912/31/2002  23:55   005XX E 89TH PL 486 BATTERY 
DOMESTIC BATTERY SIMPLE RESIDENCE   FALSE   TRUE633 6   
44  08B 1181369 1845794 20023/30/2006 21:10 41.73209609 
-87.61115533(41.732096089465905, -87.61115532670617)

2524251 HJ10017512/31/2002  23:55   012XX S KARLOV AVE  041A
BATTERY AGGRAVATED: HANDGUN SIDEWALKFALSE   FALSE   1011
24  29  04B 1149196 1894387 20023/30/2006 21:10 41.86612296 
-87.72776536(41.86612295941429, -87.72776535755746)


Like I said, the output is exactly what I want, but it doesn't seem to be 
writing to the file and I don't know why. I said I didn't know if it was 
raising an exception because I'm new to Python and I didn't know if there were 
some methods that included "silent" errors where it would continue the code but 
produce the wrong results, such as not writing my files. 

Lastly, why does everyone seem to push for os.path.join versus the method I 
have used? Is it just a 'standard' that people like to see?

Thanks for your help
-- 
https://mail.python.org/mailman/listinfo/python-list


linregress and polyfit

2013-09-17 Thread Krishnan
I created an xy pair

y = slope*x + intercept

then I added some noise to "y" using

numpy.random.normal - call it z 

I could recover the slope, intercept from (x,y) using linregress
BUT cannot calculate the slope, intercept from (x, z)

What is puzzling is that for both pairs (x,y) and (x,z) the
polyfit (order 1) works just fine (gives me the slope, intercept)
--
import numpy as np
import scipy
# create a straight line, y= slope*x + intercept 
x = np.linspace(0.0,10.0,21)  
slope = 1.0  
intercept = 3.0   
y = []  
for i in range(len(x)):  
y.append(slope*x[i] + intercept)  
# now create a data file with noise
z= []  
for i in range(len(x)):  
z.append(y[i] + 0.1*np.random.normal(0.0,1.0,1))  
# now calculate the slope, intercept using linregress
from scipy import stats  
# No error here this is OK, works for x, y
cslope, cintercept, r_value, p_value, std_err = stats.linregress(x,y)
print cslope, cintercept
# I get an error here
#ValueError: array dimensions must agree except for d_0
nslope, nintercept, nr_value, np_value, nstd_err = stats.linregress(x,z)  
print nslope, nintercept
# BUT polyfit works fine, polynomial or order 1 with both data sets
ncoeffs = scipy.polyfit(x,z,1)  
print ncoeffs
coeffs = scipy.polyfit(x,y,1)  
print coeffs
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: scipy 11 and scipy 12

2013-09-17 Thread Steven D'Aprano
On Tue, 17 Sep 2013 20:06:44 -0400, Susan Lubbers wrote:

> Our group is a python 2.7 which is installed in a shared area.  We have
> scipy 11 installed in site-packages.  How would I install scipy 12 so
> that I used the shared install of python but scipy 12 instead of 11?


If you are using Python 2.6 or better, you should be able to include the 
option "--user" when installing Scipy using either pip or distutils. I 
haven't tried these, but:

# using pip:
pip install --install-option="--user" scipy


If that fails, follow the advice given here to install from svn:
http://stackoverflow.com/questions/2213551/installing-scipy-with-pip


pip install --install-option="--user" git+http://github.com/scipy/scipy/


Otherwise, if you are installing from source using distutils, add the 
--user option directly:

python setup.py install --user scipy



Does this help?


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


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread Piet van Oostrum
Ferrous Cranus  writes:

> So cant this be done in python or not?
> or is a mtetr of configuring the MTA? conf file?

You could write a python program that uses Gmail's web interface. But it is 
tricky, and if Gmail would change its inyterface you get stuck, and have to do 
it again, risking that temporarily your email cannot be delivered.

I think you should give up this unholy idea, and just stick with the standard.
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Qt connect and first connect or unicode

2013-09-17 Thread Mohsen Pahlevanzadeh
On Tue, 2013-09-17 at 12:32 +0200, Vincent Vande Vyvre wrote:
> Le 17/09/2013 11:05, Steven D'Aprano a écrit :
> > On Tue, 17 Sep 2013 08:42:35 +0430, Mohsen Pahlevanzadeh wrote:
> >
> >> Dear all,
> >>
> >> Unfortunately, i confused and need help... the following code is:
> >> ###
> >> ##CheckBox:
> >>  QtCore.QObject.connect(self.checkBox,
> >> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
> >> self.materialsInstance.setFilterDict("C", self, "name",
> >> self.lineEdit.text()))
> >
> > I don't use Qt, but I'll try to help.
> >
> > First question, what does _fromUtf8 do? It appears to be a private
> > function. Is that your function? If you want to create a string from UTF-8
> > bytes, use:
> >
> > some_bytes.decode('utf-8')
> >
> > I don't think there is a need for a dedicated _fromUtf8 function.
> >
> > If you are using Python 3, then "toggled(bool)" is already a Unicode
> > string, and there is no need to convert from UTF-8.
> >
> > If you are using Python 2, then "toggled(bool)" is a byte string, and you
> > can turn it into a Unicode string by just using the u prefix:
> >
> > u"toggled(bool)"
> >
> > Again, no need to convert from UTF-8.
> >
> > The only time you need to convert from UTF-8 is when you are reading data
> > from a file, or other external source, that is encoded in UTF-8.
> >
> > Other than that, your first line of code seems like a straight-forward
> > call to set a callback function. When the button is pressed, the
> > instance's attribute materialsInstance calls the method setFilterDict.
> >
> >
> >>  QtCore.QObject.connect(self.checkBox_2,
> >> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
> >> self.materialsInstance.setFilterDict("C", self, "bought_price",
> >> persianToInteger(unicode(self.lineEdit_2.text()
> > Again, the same method is called, only this time with different
> > arguments. Hmmm, this strikes me as poor design. I think that a better
> > design would be for the object to have a few methods:
> >
> >  def toggle_checkbox(self, flag):
> >  # checkbox logic goes here, e.g.
> >  if flag:
> >  ...
> >  else:
> >  ...
> >
> > And then your callback is trivially
> >
> > lambda: self.toggle_checkbox(get_state)
> >
> >
> > I'm not sure how to get the checkbox state from Qt, you will need to
> > replace the "get_state" with the correct code.
> >
> > That, in my opinion, is easier to understand.
> >
> >
> >>  QtCore.QObject.connect(self.checkBox_4,
> >> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
> >> self.materialsInstance.setFilterDict("C",self,"stock",
> >> persianToInteger(unicode(self.lineEdit_3.text()
> > And more callbacks. Most of your code is probably irrelevant to the
> > problem you are having. You will help us to help you if you can read this
> > website:
> >
> > http://sscce.org/
> >
> >
> > and simplify your code.
> >
> >
> > [...many more callbacks...]
> >
> >
> >> 
> >> Description:
> >> I have 3 widget:
> >> 1. CheckBox:  a. name b. bought_price c. stock 2. LineEdit : a. name b.
> >> bought_price c. stock 3. One PushButton
> >>
> >> i have three slot: 1. responseToRequestForData()  2.setFilterDict()
> >> 3.unSetFilterDict()
> >> responseToRequestForData(): start to search in DB setFilterDict(): fill
> >> a dict from my LineEdit
> >>
> >> Problem:
> >> My name is filled in dict but its value doesn't fill up. b and c don't
> >> have any problem.
> > I'm afraid I don't understand this. Even your followup post doesn't
> > really help:
> >
> >> I see same output in console:
> >> {'stock': 2, 'name': PyQt4.QtCore.QString(u''), 'bought_price': 23}
> >
> > What result where you expecting?
> >
> > If I remember correctly, Qt strings are mutable unicode strings, so
> > 'name' is associated with an empty Qt string. If they are mutable, that
> > means that once the dict is set:
> >
> > {'name': QString(u'contents of text field'), ...}
> >
> >
> > if the text field changes, so will the string. Is that what is happening?
> >
> > (Or perhaps I have mis-remembered about Qt strings.)
> >
> > You have two callbacks that appear to set the "name" key in the dict.
> > Perhaps one of them is setting it to an empty value.
> >
> >
> >
> >
> 
> _fromUtf8 is needed for the API compatibility, at the beginning of the code 
> of Moshen it is these lines:
> 
> try:
>  _fromUtf8 = QtCore.QString.fromUtf8
> except AttributeError:
>  _fromUtf8 = lambda s: s
> 
> 
> Moshen, I thing if you pass the instance of your GUI at the class 
> materialsInstance you'll can simplify your connections
> 
> self.lineEdit.returnPressed.connect(self.materialsInstance.responseToRequestForData)
> self.lineEdit.editingFinnished.connect(self.materialsInstance.responseToRequestForData)
> 
> For the checkBoxes, I'm not sure you need all these arguments but I don't 
> know enough your code.
> 
> 
> -- 
> Vincent V.V.
>

Re: linregress and polyfit

2013-09-17 Thread Josef Pktd
On Tuesday, September 17, 2013 10:34:39 PM UTC-4, Krishnan wrote:
> I created an xy pair
> 
> 
> 
> y = slope*x + intercept
> 
> 
> 
> then I added some noise to "y" using
> 
> 
> 
> numpy.random.normal - call it z 
> 
> 
> 
> I could recover the slope, intercept from (x,y) using linregress
> 
> BUT cannot calculate the slope, intercept from (x, z)
> 
> 
> 
> What is puzzling is that for both pairs (x,y) and (x,z) the
> 
> polyfit (order 1) works just fine (gives me the slope, intercept)
> 
> --
> 
> import numpy as np
> 
> import scipy
> 
> # create a straight line, y= slope*x + intercept 
> 
> x = np.linspace(0.0,10.0,21)  
> 
> slope = 1.0  
> 
> intercept = 3.0   
> 
> y = []  
> 
> for i in range(len(x)):  
> 
> y.append(slope*x[i] + intercept)  
> 
> # now create a data file with noise
> 
> z= []  
> 
> for i in range(len(x)):  
> 
> z.append(y[i] + 0.1*np.random.normal(0.0,1.0,1))  

When z is converted to a numpy array then it has an extra dimension that 
linregress cannot handle, because np.random.normal(0.0,1.0, 1) returns an array 
and not a scalar.

much easier: use vectorized numpy instead of loop

z = y + 0.1*np.random.normal(0.0,1.0, len(y))

which is a one dimensional array and works with linregress

Josef

> 
> # now calculate the slope, intercept using linregress
> 
> from scipy import stats  
> 
> # No error here this is OK, works for x, y
> 
> cslope, cintercept, r_value, p_value, std_err = stats.linregress(x,y)
> 
> print cslope, cintercept
> 
> # I get an error here
> 
> #ValueError: array dimensions must agree except for d_0
> 
> nslope, nintercept, nr_value, np_value, nstd_err = stats.linregress(x,z)  
> 
> print nslope, nintercept
> 
> # BUT polyfit works fine, polynomial or order 1 with both data sets
> 
> ncoeffs = scipy.polyfit(x,z,1)  
> 
> print ncoeffs
> 
> coeffs = scipy.polyfit(x,y,1)  
> 
> print coeffs
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread Denis McMahon
On Wed, 18 Sep 2013 00:42:22 +0300, Ferrous Cranus wrote:

> So the foreign MTA tests for real time connectivity with the local MTA
> and it tries to detect a working host and ip address.

No.

I strongly suggest that you stop trying to write software that transmits 
data across tcp/ip networks until you understand how tcp/ip networks 
function. This NG is not a networking for dummies course.

-- 
Denis McMahon, [email protected]
-- 
https://mail.python.org/mailman/listinfo/python-list


QFrame and disable maximum attribute

2013-09-17 Thread Mohsen Pahlevanzadeh
Dear all,

I need to disbale maximum attribute , and want to fix size of my QFrame,
i set : 
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed,
QtGui.QSizePolicy.Fixed)
i attached my ui file , 
you can : pyuic4 -x myfile.ui -i output.py 
then see my attribute.

Question: How can i disable for user to couldn't maximum and minimum
attributes?

Yours,
Mohsen


materialsFindFrame.ui
Description: application/designer
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Having both if() and for() statements in one liner

2013-09-17 Thread Joshua Landau
On 18 September 2013 03:10, Steven D'Aprano  wrote:
> On Tue, 17 Sep 2013 18:54:51 +, Dave Angel wrote:
>
>> for times in range(0, 5 if person=="George" else 0):
>
>
> Oh that is evil. Truly evil.
>
> Thank you, I will treasure that piece of code forever.

range(person == "simon" and 5)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suds and Complex Sequences

2013-09-17 Thread dieter
Greg Lindstrom  writes:

> I am trying to use Suds, the very fine library allowing me to use SOAP, to
> query a service over the net.  Part of the data structure defined be the
> WSDL calls for a sequence of SubscriberDataTypes (this application is used
> to test an insurance companys' rating service).
>
> (SubscriberDataType){
>SubscriberID = None
>SubscriberBirthDate = None
>Zip = None
>
>DependentData[] = 
>  }
>
> Which goes into
>
> (MedicalRatingRequest){
>MessageHeader =
>   (MessageHeaderType){
>  MessageName = None
>  MessageID = None
>  
>   }
>RequestHeader =
>   (RequestHeaderType){
>  RequestType =
> (RequestTypeEnum){
>value = None
> }
>  
>   }
>
>SubscriberData[] = 
>  }
>
> Note that the Subscriber Data is a sequence of SubscriberDataType.  I have
> not been able to find any documentation showing me how to do this.  Does
> anyone out there know how I can generate the request?

A suds client as two major components: the "service" itself, and
the so called "factory". You can use the "factory" to create Python
objects corresponding to a type defined in the WSDL.

To pass a list of complex type, you use the factory to
create Python objects for the list components, set these objects'
attributes in any way appropriate and build of Python list of
them and assign the list or "append" them directly to the list
values attribute.

In your case, it may look somehow like:

   sd = client.factory("SubscriberDataType") # create a SubscriberDataType 
Python object
   sd.SubscriberID = ... # assign values for its attributes
   
   mrr = client.factory("MedicalRatingRequest")
   mrr.SubscriberData.append(sd) # append our "sd"
or
   mrr.SubscriberData = [sd] # assign a list

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


Re: Simple security between prototype iPhone app and SimpleHTTPServer REST service?

2013-09-17 Thread dieter
Travis Griggs  writes:

> ...
> I found a example of how to add SSL to my python service 
> (https://gist.github.com/ubershmekel/6194556). If I can figure out how to get 
> the right keys embedded into my iPhone app (it's just on my phone, not anyone 
> else's), is that enough? Or should I include some sort of auth? If so, what 
> kind? And any pointers to how to start that would be much appreciated.

This is less a Python question. What kind of authentication you
need heavily depends on which data your HTTP server publishes.
You need no authentication at all, if anyone can see this data.

There are many standards related to HTTP authentication.
Using a standard has the advantage that common components
(e.g. the browser) may have support for it.
HTTP itself defines two authentication standards - both based
an a simple "login/password" scheme: "basic" (very simple, but
prone to replay and monitoring attacks) and "digest" (more
secure but rarely used).

There is also HTTPS (that is HTTP over SSL). This is HTTP over an
encrypted communication channel. As the data transmitted
is encrypted, monitoring and replay attacks get far more difficult.
Used this way, HTTP basic authentication gets much more secure.

HTTPS is typically also used for server identification (typical
browsers warn you, if it does not trust the (HTTPS) server certificate
or the host name inside the certificate does not correspond to the
host you try to contact).
However, HTTPS can also be used with client certificates; this
usage may be an alternative to HTTP authentication.

There are a lot of further standards related to authentication:
e.g. "OpenId", "SAML2", "OpenAuth", ...


> Some have blithely replied that I should be using Flask or Tornado. I get 
> that I'm going to hit a wall with HTTPServer and that it's more of a "toy" 
> implementation.

This may be the part of your question which relates to Python; more
precisely to "HTTPServer". I do not have an authoritative answer for
you. I suppose (!; I am not sure) that "HTTPServer" will somehow
support basic authentication and maybe HTTPS, however, it
may not support it alone.

For "basic" authentication, you need some kind of user "database"
which records the known users with their passwords and maybe
the services those users may use.
By itself "HTTPS" does not provide (client) authentication;
for client authentication, you need again some kind of
user "database" to determine which clients (identified by the
client certificate) you want to grant any and which services.

This user "database" may be quite simple (maybe, it contains just "you") -
but Python's "HTTPServer" cannot know - and does not provide
this piece of infrastructure. You must extend Python's
"HTTPServer" to provide it.

Authentication support is a fundamental task for web frameworks.
Therefore, they contain infrastructure to facilitate this task.
This include "modules" for the implementation of the "user database"
mentioned above.


My personal recommendation: if this is the only web application
you plan to implement, you may stick with "HTTPServer".
However, if you can imagine that in the future you
will implement further web applications, then look for a
web framework. True, you will have to learn quite a bit -
but you get components that facilitate typical tasks related
to web applications (e.g. authentication).
This initial learning effort may amortise when you plan
to implement more web applications in the future.

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