Re: How to add ftp put function in PyQT network ftp demo

2014-07-02 Thread 不坏阿峰
在 2014年7月1日星期二UTC+7下午5时27分59秒,不坏阿峰写道:
> I want to modify the pyqt network ftp demo to include an upload function, but 
> I am failing. Could someone can show me how to do this? I have tried to add 
> this code, but it does not work. 
> 
> [Orignal 
> demo]https://github.com/Werkov/PyQt4/blob/master/examples/network/ftp/ftp.py
> 
> 
> 
> at First, i add these code into demo. not work at all
> 
> ##
> 
> buttonBox.addButton(self.uploadButton,
> 
> QtGui.QDialogButtonBox.ActionRole)
> 
> self.uploadButton = QtGui.QPushButton("upload")
> 
> self.uploadButton.clicked.connect(self.selectFile)
> 
> 
> 
> def selectFile(self):
> 
> self.filename =QtGui.QFileDialog.getOpenFileName()
> 
> up_fname = re.sub(r".*/","",self.filename)
> 
> upload_file = QtCore.QFile(self.filename)
> 
> self.ftp.put(upload_file, up_fname)
> 
> 
> 
> ##
> 
> 
> 
> Second, i modify like this, i can upload small file successfully, but fail on 
> big size file, the app will crash.
> 
> 
> 
> #
> 
> def selectFile(self):
> 
> self.filename =QtGui.QFileDialog.getOpenFileName()
> 
> print self.filename
> 
> up_fname = re.sub(r".*/","",self.filename)
> 
> print up_fname
> 
> 
> 
> 
> 
> upload_file = QtCore.QFile(self.filename)
> 
> #print upload_file
> 
> upload_file.open(QtCore.QIODevice.ReadOnly)
> 
> ba = QtCore.QByteArray()
> 
> ba.append(upload_file.readAll())
> 
> 
> 
> #buffer = QtCore.QBuffer() do not how to use Buffer
> 
> #buffer.open(QtCore.QIODevice.ReadWrite)
> 
> #buffer.setData(ba)
> 
> 
> 
> self.ftp.put(ba, up_fname)
> 
> self.progressDialog.setLabelText("Uploading %s..." % up_fname)
> 
> self.uploadButton.setEnabled(False)
> 
> self.progressDialog.exec_()
> 
> self.uploadButton.setEnabled(True)
> 
> self.ftp.list()
> 
> 
> 
> 

any one can give some suggestion?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Get named groups from a regular expression

2014-07-02 Thread Devin Jeanpierre
On Tue, Jul 1, 2014 at 8:58 AM, Chris Angelico  wrote:
> On Wed, Jul 2, 2014 at 1:29 AM, Peter Otten <__pete...@web.de> wrote:
>> Easy, just write a regular expression to parse regular expressions ;)
>
> Hmm, is that even possible? AIUI you can't make a regex that correctly
> parses nested tokens, and named groups can definitely be nested.

Nesting isn't inherently a problem. Since nesting doesn't change the
way they parse, you can ignore nesting for the purposes of pulling out
named groups. Find each unescaped "(?P<...>".

(Making sure they are unescaped is annoying, though.)

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


Statically type-checked variant of Python

2014-07-02 Thread musicdenotation
PHP has Hack, JavaScript has TypeScript, Python has what?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Success with subprocess communicate on Windows?

2014-07-02 Thread Terry Reedy

On 7/2/2014 12:33 AM, Tim Roberts wrote:

Terry Reedy  wrote:


It does not work on Windows. As I reported on
http://bugs.python.org/issue8631, msg222053,

subprocess.check_output("pyflakes -h")

works in the interpreter and Idle shell, while

s.check_output("pyflakes c:\programs\python34\lib\turtle.py")

gives bizarre output in the interpreter and hangs in the idle shell, as
does the code above.


Right.  What do you think \t is in a string?  (Hint: it's only one byte.)


Yes, how could I forget that. But my use of a string literal here does 
not explain the problems when used string variables, as generated by os. 
I should try printing out the list of args passed to subprocess.


While remembering what \t is explains the command interpreter output 
(recursing through /lib), it does not explain the difference when 
invoked from Idle. There seems to be some bad interaction when calling 
subprocesses in the user subprocess.



You need to use
 s.check_output("pyflakes c:\\programs\\python34\\lib\\turtle.py")
or
 s.check_output(r"pyflakes c:\programs\python34\lib\turtle.py")


Now I get "Command 'pyflakes c:\programs\python34\lib\turtle.py' returns 
non-zero exit status 1" on both. On Idle, as least, a command-prompt 
window is flashed/displayed. It makes no sense to me that in the command 
interpreter,

'pyflakes c:\\programs\\python34\\lib' works and
'pyflakes c:\\programs\\python34\\lib\\turtle.py' returns status 1.
whereas both (with quotes elided and undoubled \) work at the command 
prompt.


--
Terry Jan Reedy

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


Re: fixing an horrific formatted csv file.

2014-07-02 Thread flebber
> >>> TM = TX.Table_Maker (headings = 
> ('Meeting','Date','Race','Number','Name','Trainer','Location')) 
> >>> TM (race_table (your_csv_text)).write () 

Where do I find TX? Found this mention in the list, was it available in pip by 
any name?
https://mail.python.org/pipermail/python-list/2014-February/667464.html

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


Re: Searching for lots of similar strings (filenames) in sqlite3 database

2014-07-02 Thread Adam Funk
On 2014-07-01, Chris Angelico wrote:

> On Wed, Jul 2, 2014 at 1:15 AM, Adam Funk  wrote:
>> On 2014-07-01, Chris Angelico wrote:
>>
>>> On Tue, Jul 1, 2014 at 9:26 PM, Adam Funk  wrote:
 cursor.execute('SELECT filename FROM files WHERE filename IS ?', 
 (filename,))
>>>
>>> Shouldn't this be an equality check rather than IS, which normally I'd
>>> expect to be "IS NULL" or "IS NOT NULL"?
>>
>> Oh, it probably should be in "heavy" SQL.  In SQLite, '==', '=', &
>> 'IS' are interchangeable.
>>
>> http://www.tutorialspoint.com/sqlite/sqlite_operators.htm
>
> Ah, okay. In that case, I'd advise going with either == for
> consistency with the rest of Python, or (preferably) = for consistency
> with other SQL engines. You wouldn't use "is" to test if two Python
> strings are equal, so there's no particular reason to use it here :)

I agree.

>> Oh, even better:
>>
>> add_files = listing - known_files
>> delete_files = known_files - listing
>>
>> and then I can remove files that have disappeared off the spool from
>> the table.  Thanks very much!
>
> Ah! Didn't know that was a valuable feature for you, but getting that
> "for free" is an extra little bonus, so that's awesome!

I didn't know it was a valuable feature until I saw that easy way to
do it!  This will keep the database from growing indefinitely, though.



-- 
'...and Tom [Snyder] turns to him and says, "so Alice [Cooper], is it
true you kill chickens on stage?"  That was the opening question, and
Alice looks at him real serious and goes, "Oh no, no no.  That's
Colonel Sanders.  Colonel Sanders kills chickens."'
-- 
https://mail.python.org/mailman/listinfo/python-list


How can I catch values from other def by flask???

2014-07-02 Thread fk26541598fk
this is my code


def aa():
if request.method=='POST':
get_test(value1)
return value1
else:
get_test(value2)
return value2
return 'it does not work'

def post_test(value1):
value1='POST it works'
return value1
def get_test(value2):
value2='GET it works'



how can i catch post_test value1 to aa() return???

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


Re: Searching for lots of similar strings (filenames) in sqlite3 database

2014-07-02 Thread Adam Funk
On 2014-07-01, Chris Angelico wrote:

> On Wed, Jul 2, 2014 at 1:15 AM, Adam Funk  wrote:
>> On 2014-07-01, Chris Angelico wrote:

>>> There is one critical consideration, though. What happens if the
>>> directory name contains an underscore or percent sign? Or can you
>>> absolutely guarantee that they won't? You may need to escape them, and
>>> I'm not sure how SQLite handles that. (Possibly \_ will match literal
>>> _, and \\ will match literal \, or something like that.)
>>
>> I can guarantee that the directory names are all
>> '/var/spool/news/message.id/' then 3 digits.  (The filenames are
>> pretty wild, since they are MIDs.)  AIUI, using the '?' substitution
>> in the sqlite3 library is supposed to be safe.
>
> This is nothing to do with question-mark substitution. There are two
> separate levels of character significance here - it's like a quoted
> string with a regex. Suppose you want to make a regex that searches
> for an apostrophe. If you try to define that in a single-quoted
> string, you need to escape it:
>
> regex = '^\'$'
>
> However, if you ask the user to enter a regex, that wouldn't be necessary:
>
> regex = input("Enter a pattern: ") # raw_input in Python 2
> Enter a pattern: ^'$
>
> This is what the question mark substitution is like - it avoids the
> need to carefully manage string delimiters and so on. However, if you
> want to make a regex that searches for a backslash, then you need to
> escape it, because the backslash is important to the regex itself. In
> the same way, the underscore and percent sign are significant to the
> LIKE operator. If it were possible to have a directory name with a
> percent sign in it, it would match far too much - because you'd
> construct a LIKE pattern something like (ahem)
> "/var/spool/news/message%20id/142/%" - and as you can see, the percent
> sign at the end is no different from the percent sign in the middle.
>
> But you're safe because you know your data, unrelated to your
> substitution method. Possibly merits a comment... but possibly not
> worth it.

Well, I've changed it to the following anyway.

subdir_glob = subdir + '/*'
cursor.execute('SELECT filename FROM files WHERE filename GLOB ?',
   (subdir_glob,))
rows = cursor.fetchall()
known_files = {row[0] for row in rows}

I see what you mean about paths containing '%', but I don't see why
you were concerned about underscores, though.


-- 
You know, there are many people in the country today who, through no
fault of their own, are sane. Some of them were born sane. Some of
them became sane later in their lives.--― Graham Chapman
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Searching for lots of similar strings (filenames) in sqlite3 database

2014-07-02 Thread Chris Angelico
On Wed, Jul 2, 2014 at 7:32 PM, Adam Funk  wrote:
> Well, I've changed it to the following anyway.
>
> subdir_glob = subdir + '/*'
> cursor.execute('SELECT filename FROM files WHERE filename GLOB ?',
>(subdir_glob,))
> rows = cursor.fetchall()
> known_files = {row[0] for row in rows}
>
> I see what you mean about paths containing '%', but I don't see why
> you were concerned about underscores, though.

With GLOB, presumably ? matches a single character and * matches any
number of characters. With LIKE, _ matches a single character and %
matches any number. So, for instance, WHERE filename LIKE
'/foo/bar/spam_spam/%' will match '/foo/bar/spam2spam/1234', which may
be a little surprising. It's not going to be a serious problem in most
cases, as it'll also match '/foo/bar/spam_spam/1234', but the false
positives will make one of those "Huh" moments if you don't
keep an eye on your magic characters.

In your specific case, you happen to be safe, but as I look over the
code, my paranoia kicks in and tells me to check :) It's just one of
those things that flags itself to the mind - anything that might help
catch bugs early is a good feature of the mind, in my opinion!

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


Re: Statically type-checked variant of Python

2014-07-02 Thread Steven D'Aprano
On Wed, 02 Jul 2014 15:26:07 +0700, musicdenotation wrote:

> PHP has Hack, JavaScript has TypeScript, Python has what?

I don't know if this counts, but there's Cobra:

http://cobra-language.com/

http://cobra-language.com/docs/python/

Cobra has a lot more than just (optional) static typing. Some of the 
features strike me as good ideas, such as contracts and unit tests, some 
as dubious (there's a lot of changes to the syntax which, in my opinion, 
hurt readability). But overall, it strikes me as a very exciting language.


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


Re: How can I catch values from other def by flask???

2014-07-02 Thread Steven D'Aprano
On Wed, 02 Jul 2014 02:43:28 -0700, fk26541598fk wrote:

> this is my code


Change the code as shown below:

> def aa():
> if request.method=='POST':
> get_test(value1)
> return value1

def aa():
if request.method=='POST':
value1 = post_test()
return value1

> else:
> get_test(value2)
> return value2

else:
value2 = get_test()
return value2


> return 'it does not work'
> 
> def post_test(value1):
> value1='POST it works'
> return value1

def post_test():
return 'POST it works'


> def get_test(value2):
> value2='GET it works'

def get_test():
return 'GET it works'



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


Re: Searching for lots of similar strings (filenames) in sqlite3 database

2014-07-02 Thread Adam Funk
On 2014-07-02, Chris Angelico wrote:

> On Wed, Jul 2, 2014 at 7:32 PM, Adam Funk  wrote:
>> Well, I've changed it to the following anyway.
>>
>> subdir_glob = subdir + '/*'
>> cursor.execute('SELECT filename FROM files WHERE filename GLOB ?',
>>(subdir_glob,))
>> rows = cursor.fetchall()
>> known_files = {row[0] for row in rows}
>>
>> I see what you mean about paths containing '%', but I don't see why
>> you were concerned about underscores, though.
>
> With GLOB, presumably ? matches a single character and * matches any
> number of characters. With LIKE, _ matches a single character and %
> matches any number. So, for instance, WHERE filename LIKE
> '/foo/bar/spam_spam/%' will match '/foo/bar/spam2spam/1234', which may
> be a little surprising. It's not going to be a serious problem in most
> cases, as it'll also match '/foo/bar/spam_spam/1234', but the false
> positives will make one of those "Huh" moments if you don't
> keep an eye on your magic characters.
>
> In your specific case, you happen to be safe, but as I look over the
> code, my paranoia kicks in and tells me to check :) It's just one of
> those things that flags itself to the mind - anything that might help
> catch bugs early is a good feature of the mind, in my opinion!

Oh, I'd just missed the '_' in the LIKE documentation.  Doh!


-- 
Indentation is for enemy skulls, not code!
--- Klingon Programmer's Guide
-- 
https://mail.python.org/mailman/listinfo/python-list


NEW JOB req: Python developer with Analytical risk

2014-07-02 Thread Suman Bharathi Balasubramanian
Python Developers with Analytical Risk Exp- NYC, Long Island, Wilmington, 
Columbus, Dallas
6 months plus 
* Implement statistical, economic, econometric or other mathematical 
models/code for Client's bank models in Python
* Ability to translate existing Excel / SAS Model implementations into 
requirements and high-performance Python implementation
* Work with Enterprise Data Warehouse (ICDW/Teradata) staff members to map 
variables from their source systems to tables and data sets used by the 
modeling team and to create necessary meta data to document sources and field 
definitions
* Responsible for all aspects of data management for the modeling team, data 
sourcing into containers (Numpy/Pandas), Documentation(Sphynx), Acceleration, 
(Numba/Cython) and graphics (Matplotlib/Ggplot/Bokeh)
* Assist modeling team members with questions surrounding sources of data files 
and definitions of data fields
* Develop and maintain report-writing programs used by modeling team members.

* Application Developer (Ad Hoc/Statistical Programmer) with 7+ experience 
years in Python
* Experience with Python programming using Data Containers (Numpy/Pandas), 
Documentation (Sphynx), Acceleration, (Numba/Cython) and graphics 
(Matplotlib/Ggplot/Bokeh)
* Translate Excel / SAS Model Implementations into Python
* Ability to produce queries/tables on request - Sourced from Oracle / Teradata 
Databases
* Preference will be provided to those with demonstrated modeling experience in 
consumer and retail business banking
* Excellent communication skills, as the incumbent will frequently be called 
upon to make presentations to senior management and to write documents that 
describe work products in a clear manner.

regards,
suma...@sstech.us
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 1-0.95

2014-07-02 Thread Steven D'Aprano
On Tue, 01 Jul 2014 14:17:14 -0700, Pedro Izecksohn wrote:

> pedro@microboard:~$ /usr/bin/python3
> Python 3.3.2+ (default, Feb 28 2014, 00:52:16) [GCC 4.8.1] on linux
> Type "help", "copyright", "credits" or "license" for more information.
 1-0.95
> 0.050044
 
 
>   How to get 0.05 as result?

Oh, this is a fantastic example of the trouble with floating point! Thank 
you for finding it!


py> 0.05
0.05
py> 1 - 0.95
0.050044
py> 1 - 0.9 - 0.05
0.049975
py> 1 - 0.5 - 0.45
0.04999


*This is not a Python problem*

This is a problem with the underlying C double floating point format. 
Actually, it is not even a problem with the C format, since this problem 
applies to ANY floating point format, consequently this sort of thing 
plagues *every* programming language (unless they use arbitrary-precision 
rationals, but they have their own problems).

In this *specific* case, you can get better (but slower) results by using 
the Decimal format:

py> from decimal import Decimal
py> 1 - Decimal("0.95")
Decimal('0.05')


This works because the Decimal type stores numbers in base 10, like you 
learned about in school, and so numbers that are exact in base 10 are 
(usually) exact in Decimal. However, the built-in float stores numbers in 
base 2, for speed and accuracy. Unfortunately many numbers which are 
exact in base 10 are not exact in base 2. Let's look at a simple number 
like 0.1 (in decimal), and try to calculate it in base 2:

0.1 in binary (0.1b) equals 1/2, which is too big.

0.01b equals 1/4, which is too big.

0.001b equals 1/8, which is too big.

0.0001b equals 1/16, which is too small, so the answer lies somewhere 
between 0.0001b and 0.001b.

0.00011b equals 1/16 + 1/32 = 3/32, which is too small.

0.000111b equals 1/16 + 1/32 + 1/64 = 7/64, which is too big, so the 
answer lies somewhere between 0.000111b and 0.00011b.

If you keep going, you will eventually get that the decimal 0.1 written 
in base 2 is .000110011001100110011001100110011... where the "0011" 
repeats forever. (Just like in decimal, where 1/3 = 0.3... repeating 
forever.) Since floats don't use an infinite amount of memory, this 
infinite sequence has to be rounded off somewhere. And so it is that 0.1 
stored as a float is a *tiny* bit larger than the true decimal value 0.1:


py> Decimal.from_float(0.1)
Decimal('0.155511151231257827021181583404541015625')


All the troubles with floating point numbers start with this harsh 
reality, numbers have to be rounded off somewhere lest they use infinite 
memory, and that rounding introduces errors into the calculation. 
Sometimes those errors cancel, and sometimes they reinforce.

To understand what is going on in more detail, you can start with these 
links:

https://docs.python.org/2/faq/design.html#why-am-i-getting-strange-results-with-simple-arithmetic-operations

http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

http://effbot.org/pyfaq/why-are-floating-point-calculations-so-inaccurate.htm

http://blog.codinghorror.com/why-do-computers-suck-at-math/

https://randomascii.wordpress.com/category/floating-point/

https://www.gnu.org/software/gawk/manual/html_node/Floating-Point-Issues.html


Good luck!


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


Re: fixing an horrific formatted csv file.

2014-07-02 Thread F.R.

On 07/02/2014 11:13 AM, flebber wrote:

TM = TX.Table_Maker (headings =

('Meeting','Date','Race','Number','Name','Trainer','Location'))

TM (race_table (your_csv_text)).write ()

Where do I find TX? Found this mention in the list, was it available in pip by 
any name?
https://mail.python.org/pipermail/python-list/2014-February/667464.html

Sayth


I'd have to make it available. I proposed it some time ago and received 
a couple of suggestions in return. It is a modular transformation 
framework written entirely in python (2.7). It consists essentially of a 
base class "Transformer" that handles input and output in such a way 
that Transformer objects can be chained. It saved me from drowning an a 
horrible and growing tangle of hacks. Finding something usable I had 
previously done took time. Understanding how it worked took more time 
and adapting it took still more time, so that writing yet another hack 
from scratch was faster.
A number of hacks I could quickly wrap into a Transformer object 
and so could start building a library of standard Transformers. The 
Table_Maker is one of them. The table making code is quite bad. It 
suffers from feature overload. I would clean it up for distribution.
I'd be happy to distribute the base class and a few standard 
Translators, such as I use every day. (File Reader, File Writer, DB Run 
Command, DB Write, Table Maker, PDF To Text, Text To Lines, Lines To 
Text, Sort, Sort And Unique, etc.) Writing one's own Transformers is a 
breeze. Testing too, because a Transformer keeps its input and output 
and, in line with the system's design philosophy, does only its own 
single thing.
A Chain is a list of Transformers that run in sequence. It is 
itself derived from Transformer and is a functional equivalent. So 
Chains nest. Fixing a Chain that nothing comes out of is a 
straightforward matter too. It will still have run up to the failing 
element. Chain.show () reveals the culprit as the first one to have no 
output.
I am not up to date on distributing and would depend on qualified 
help on that.


Frederic





A brief overview


The TX solution to your race table would be (TX is the name of the module):

class Race_Table (TX.Transformer):
'''
In: CSV text
Out: Tabular data (2-dimensional list)
'''
name = 'Race_Table'
@TX.setup   # Checks timestamps to prevent needless reruns in 
the absence of new input

def transform (self):
for line in self.Input.data:
# See my post
self.Output.take (output_table)

Example file to file:
>>> Race_Schedule_F2F = TX.Chain (TX.File_Reader (), Race_Table (), 
TX.List_To_CSV (delimiter = ';'), TX.File_Writer (terminal = out_file_name)

>>> Race_Schedule_F2F (input_file_name)   # Does it all!

Example web to database:
>>> Race_Schedule_WWW2DB = TX.Chain (TX.WWW_Reader (), 
Race_Schedule_HTML_Reader (), Race_Table (), TX.DB_Writer (table_name = 
'horses'))
>>> Race_Schedule_WWW2DB (url)   # Does is all! You'd have to write 
the Race_Schedule_HTML_Reader


Verify your table:
>>> Table_Viewer = TX.Chain (TX.Table_Maker (), TX.Table_Writer ())
>>> Race_Schedule_WWW2DB.show_tree () # See which one should display
Chain
Chain[0] - WWW Reader
Chain[1] - Race_Schedule_HTML_Reader
Chain[2] - Race_Table
Chain[3] - DB Writer
>>> print Table_Viewer (Race_Schedule_WWW2DB[2]()) # All 
Transformers keep their data

(Display of table)

Verify database:
>>> print Table_Viewer (TX.DB_Reader (table_name = 'horses')())
(Display of database table)

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


Re: 1-0.95

2014-07-02 Thread Marko Rauhamaa
Steven D'Aprano :

> This is a problem with the underlying C double floating point format.
> Actually, it is not even a problem with the C format, since this
> problem applies to ANY floating point format, consequently this sort
> of thing plagues *every* programming language (unless they use
> arbitrary-precision rationals, but they have their own problems).

Actually, it is not a problem at all. Floating-point numbers are a
wonderful thing.

> This works because the Decimal type stores numbers in base 10, like you 
> learned about in school, and so numbers that are exact in base 10 are 
> (usually) exact in Decimal.

Exactly, the problem is in our base 10 mind. Note, however:

   >>> Decimal(1) / Decimal(3) * Decimal(3)
   Decimal('0.')

Even "arbitrary-precision" rationals would suffer from the same problem:

   >>> Rational(2).sqrt() * Rational(2).sqrt() == Rational(2)
   False

Yes, I'm making it up, but it's still true.


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


Re: Success with subprocess communicate on Windows?

2014-07-02 Thread Wolfgang Maier

On 02.07.2014 11:05, Terry Reedy wrote:

On 7/2/2014 12:33 AM, Tim Roberts wrote:

Terry Reedy  wrote:

You need to use
 s.check_output("pyflakes c:\\programs\\python34\\lib\\turtle.py")
or
 s.check_output(r"pyflakes c:\programs\python34\lib\turtle.py")


Now I get "Command 'pyflakes c:\programs\python34\lib\turtle.py' returns
non-zero exit status 1" on both. On Idle, as least, a command-prompt
window is flashed/displayed. It makes no sense to me that in the command
interpreter,
'pyflakes c:\\programs\\python34\\lib' works and
'pyflakes c:\\programs\\python34\\lib\\turtle.py' returns status 1.
whereas both (with quotes elided and undoubled \) work at the command
prompt.



I am not 100% sure whether that is the problem, but from what I gather 
from the subprocess module docs the args string is passed to the Windows 
CreateProcess function as a single string.
To me this seems to imply that it is passed as the lpCommandLine 
parameter (with Null for the lpApplicationName parameter).
This is what Microsoft says about this case 
(http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx):



If lpApplicationName is NULL, the first white space–delimited token of 
the command line specifies the module name. If you are using a long file 
name that contains a space, use quoted strings to indicate where the 
file name ends and the arguments begin (see the explanation for the 
lpApplicationName parameter). If the file name does not contain an 
extension, .exe is appended. Therefore, if the file name extension is 
.com, this parameter must include the .com extension. If the file name 
ends in a period (.) with no extension, or if the file name contains a 
path, .exe is not appended. If the file name does not contain a 
directory path, the system searches for the executable file in the 
following sequence.



So in your case the default behavior would be to add an .exe extension 
to pyflakes, which is probably not what you intended ?


Best,
Wolfgang

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


Re: 1-0.95

2014-07-02 Thread Skip Montanaro
On Wed, Jul 2, 2014 at 11:59 AM, Marko Rauhamaa  wrote:
> Yes, I'm making it up, but it's still true.

I don't think there's any reason to be hypothetical:

In [149]: d
Out[149]: Decimal('2')

In [150]: d.sqrt() * d.sqrt() == d
Out[150]: False

:-)

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


Re: Success with subprocess communicate on Windows?

2014-07-02 Thread Wolfgang Maier

On 02.07.2014 19:31, Wolfgang Maier wrote:


I am not 100% sure whether that is the problem, but from what I gather
from the subprocess module docs the args string is passed to the Windows
CreateProcess function as a single string.
To me this seems to imply that it is passed as the lpCommandLine
parameter (with Null for the lpApplicationName parameter).
This is what Microsoft says about this case
(http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx):



If lpApplicationName is NULL, the first white space–delimited token of
the command line specifies the module name. If you are using a long file
name that contains a space, use quoted strings to indicate where the
file name ends and the arguments begin (see the explanation for the
lpApplicationName parameter). If the file name does not contain an
extension, .exe is appended. Therefore, if the file name extension is
.com, this parameter must include the .com extension. If the file name
ends in a period (.) with no extension, or if the file name contains a
path, .exe is not appended. If the file name does not contain a
directory path, the system searches for the executable file in the
following sequence.


So in your case the default behavior would be to add an .exe extension
to pyflakes, which is probably not what you intended ?

Best,
Wolfgang



Ah, I forgot about your pyflakes -h example, which works, so my 
explanation must be wrong.

Sorry.

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


Re: NEW JOB req: Python developer with Analytical risk

2014-07-02 Thread Mark Lawrence

On 02/07/2014 14:44, Suman Bharathi Balasubramanian wrote:

Please post your jobs here https://www.python.org/community/jobs/

--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


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


Re: 1-0.95

2014-07-02 Thread Steven D'Aprano
On Wed, 02 Jul 2014 19:59:25 +0300, Marko Rauhamaa wrote:

> Steven D'Aprano :
> 
>> This is a problem with the underlying C double floating point format.
>> Actually, it is not even a problem with the C format, since this
>> problem applies to ANY floating point format, consequently this sort of
>> thing plagues *every* programming language (unless they use
>> arbitrary-precision rationals, but they have their own problems).
> 
> Actually, it is not a problem at all. Floating-point numbers are a
> wonderful thing.

No, *numbers* in the abstract mathematical sense are a wonderful thing. 
Concrete floating point numbers are a *useful approximation* to 
mathematical numbers. But they're messy, inexact, and fail to have the 
properties we expect real numbers to have, e.g. any of these can fail 
with IEEE-754 floating point numbers:

1/(1/x) == x

x*(y+z) == x*y + x*z

x + y - z == x - z + y

x + y == x implies y == 0

You think maths is hard? That's *nothing* compared to reasoning about 
floating point numbers, where you cannot even expect x+1 to be different 
from x.

In the Bad Old Days before IEEE-754, things were even worse! I've heard 
of CPUs where it was impossible to guard against DivideByZero errors:

if x != 0:  # succeeds
print 1/x  # divide by zero

because the test for inequality tested more digits than the divider used. 
Ouch.


>> This works because the Decimal type stores numbers in base 10, like you
>> learned about in school, and so numbers that are exact in base 10 are
>> (usually) exact in Decimal.
> 
> Exactly, the problem is in our base 10 mind.

No no no no! The problem is that *no matter what base you pick* some 
exact rational numbers cannot be represented in a finite number of digits.

(Not to mention the irrationals.)



> Note, however:
> 
>>>> Decimal(1) / Decimal(3) * Decimal(3)
>Decimal('0.')

Yes! Because Decimal has a finite (albeit configurable) precision, while 
1/3 requires infinite number of decimal places. Consequently, 
1/Decimal(3) is a little bit smaller than 1/3, and multiplying by 3 gives 
you something a little bit smaller than 1.

Ironically, in base 2, the errors in that calculation cancel out:

py> 1/3*3 == 1
True


and of course in base 3 the calculation would be exact.


> Even "arbitrary-precision" rationals would suffer from the same problem:

Not so.

py> from fractions import Fraction
py> Fraction(1, 3)*3 == 1
True

"Arbitrary precision" rationals like Fraction are capable of representing 
*every rational number* exactly (provided you have enough memory).


>>>> Rational(2).sqrt() * Rational(2).sqrt() == Rational(2)
>False

Square root of 2 is not a rational number.



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


Re: general module auditing

2014-07-02 Thread Irmen de Jong
On 2-7-2014 4:04, Rita wrote:
> yes, this helps. But I want to know who uses the module, serpent. So, when
> I upgrade it or remove it they won't be affected adversely.


(Please don't top-post, it makes the discussion harder to follow.)


> On Tue, Jul 1, 2014 at 2:16 PM, Irmen de Jong 
> wrote:
> 
>> On 1-7-2014 12:38, Rita wrote:
>>> i work in a group of developers (15 or so)  who are located globally. I
>>> would like to know what modules everyone is uses if I ever have to
>> upgrade
>>> my python. Is there mechanism which will let me see who is using what?
>>>
>>> ie,
>>>
>>> tom,matplotlib
>>> bob, pylab
>>> nancy, numpy
>>> nancy, matplotlib
>>>
>>> etc...
>>>
>>>
>>
>> Well, if your group is all using Pip (and perhaps even virtualenv), you
>> could use pip
>> list. In my case:
>>
>> $ pip list

[...]


Why would the fact that you upgrade or remove a package, affect another 
developer in
your group? Are you all using the same machine to develop on, with one Python 
installation?

I think you'll have to tell us some more details about the way you work 
together before
we can give a meaningful answer to your question.


Irmen

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


OOP with MyTime

2014-07-02 Thread kjakupak
I'm trying to write a boolean function that takes two Mytime objects, t1 and t2 
as arguments, and returns True if the object falls inbetween the two times.

This is a question from the How to Think Like a Computer Scientist book, and I 
need help.

What I've gotten so far:

class MyTime:
def __init__(self, hrs=0, mins=0, secs=0):
self.hours = hrs
self.minutes = mins
self.seconds = secs
def between(t1, t2):
if float(t1 <= t3) and float(t3 < t2):
return True
else:
return False

I just don't understand how to make a function that uses MyTime objects into 
the boolean function? Any help would be great.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OOP with MyTime

2014-07-02 Thread Akira Li
kjaku...@gmail.com writes:

> I'm trying to write a boolean function that takes two Mytime objects, t1 and 
> t2 as arguments, and returns True if the object falls inbetween the two times.
>
> This is a question from the How to Think Like a Computer Scientist book, and 
> I need help.
>
> What I've gotten so far:
>
> class MyTime:
> def __init__(self, hrs=0, mins=0, secs=0):
> self.hours = hrs
> self.minutes = mins
> self.seconds = secs
> def between(t1, t2):
> if float(t1 <= t3) and float(t3 < t2):
> return True
> else:
> return False
>
> I just don't understand how to make a function that uses MyTime objects into 
> the boolean function? Any help would be great.

A method accepts the object itself as the first parameter:

  import functools

  @functools.total_ordering
  class MyTime:
...
def inbetween(self, t1, t2):
"""Return whether `self` is in [t1, t2) right-open range."""
return t1 <= self < t2 # `self` is the object itself
def _astuple(self):
return (self.hours, self.minutes, self.seconds)
def __lt__(self, other):
"""Return whether `self < other`."""
return self._astuple() < other._astuple()
def __eq__(self, other):
"""Return whether `self == other`."""
return self._astuple() == other._astuple()

See
https://docs.python.org/3/library/functools.html#functools.total_ordering

Example:

  >>> MyTime(1).inbetween(MyTime(0), MyTime(2))
  True

It is equivalent to:

  >>> MyTime(0) <= MyTime(1) < MyTime(2)
  True


--
Akira

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


Re: OOP with MyTime

2014-07-02 Thread MRAB

On 2014-07-02 20:20, kjaku...@gmail.com wrote:

I'm trying to write a boolean function that takes two Mytime objects, t1 and t2 
as arguments, and returns True if the object falls inbetween the two times.

This is a question from the How to Think Like a Computer Scientist book, and I 
need help.

What I've gotten so far:

class MyTime:
 def __init__(self, hrs=0, mins=0, secs=0):
 self.hours = hrs
 self.minutes = mins
 self.seconds = secs
 def between(t1, t2):
 if float(t1 <= t3) and float(t3 < t2):
 return True
 else:
 return False

I just don't understand how to make a function that uses MyTime objects into 
the boolean function? Any help would be great.


If you want 'between' to be an instance method of the MyTime class, it
needs 'self' as well as the 2 arguments 't1' and 't2'.

You can then compare the hours, minutes and seconds of self against
those of t1 and t2:

def between(self, t1, t2):
return (t1.hours, t1.minutes, t1.seconds) <= (self.hours, 
self.minutes, self.seconds) and (self.hours, self.minutes, self.seconds) 
<= (t2.hours, t2.minutes, t2.seconds)


That could be shortened further using chained comparisons.

Note that the code assumes that the times t1 and t2 are ordered, i.e.
that time t1 is not later/greater than time t2.
--
https://mail.python.org/mailman/listinfo/python-list


Re: 1-0.95

2014-07-02 Thread Marko Rauhamaa
Steven D'Aprano :

>>>>> Rational(2).sqrt() * Rational(2).sqrt() == Rational(2)
>>False
>
> Square root of 2 is not a rational number.

Nobody said it was. It's just that even "arbitrary-precision" rational
numbers wouldn't free you from the issues of floating-point numbers. The
Decimal number class won't do it, either, of course.

On the other hand, floating-point numbers are perfect whenever you deal
with science and measurement. And when you deal with business (= money),
integers are the obvious choice.

I would venture to say that the real applications for Decimal are very
rare. In practice, I'm afraid, people with rather a weak understanding
of numbers and computation might gravitate toward Decimal unnecessarily.


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


FW: install software via Python script

2014-07-02 Thread Moshe Avraham
 

HI Guys,

I need to install variety of software (Oracle, SqlServer, upgrade JAVA
version, WAS, WMB, Tomcat, etc.) on both WINDOWS and UNIX/LINUX.

These are usual daily operation of large IT departments.

So instead of developing both shell & DOS scripts, I like to develop a
single Python script (for each of these software) to run on all operation
systems.

Can someone suggest an easy simple way of developing a script for Oracle (as
an example).

Thanks,

Moshe

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


Re: FW: install software via Python script

2014-07-02 Thread Grant Edwards
On 2014-07-02, Moshe Avraham  wrote:

> I need to install variety of software (Oracle, SqlServer, upgrade
> JAVA version, WAS, WMB, Tomcat, etc.) on both WINDOWS and UNIX/LINUX.
>
> These are usual daily operation of large IT departments.
>
> So instead of developing both shell & DOS scripts, I like to develop
> a single Python script (for each of these software) to run on all
> operation systems.
>
> Can someone suggest an easy simple way of developing a script for
> Oracle (as an example).


 1. Write down a precise description of each of the steps required to
accomplish the task.

 2. Convert each step to Python.

-- 
Grant Edwards   grant.b.edwardsYow! I am NOT a nut
  at   
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: install software via Python script

2014-07-02 Thread Paul Sokolovsky
Hello,

On Wed, 2 Jul 2014 18:01:45 -0400
"Moshe Avraham"  wrote:

> HI Guys,
> 
> I need to install variety of software (Oracle, SqlServer, upgrade JAVA
> version, WAS, WMB, Tomcat, etc.) on both WINDOWS and UNIX/LINUX.
> 
> These are usual daily operation of large IT departments.
> 
> So instead of developing both shell & DOS scripts, I like to develop a
> single Python script (for each of these software) to run on all
> operation systems.
> 
> Can someone suggest an easy simple way of developing a script for
> Oracle (as an example).

You should look into Ansible http://www.ansible.com ,
https://github.com/ansible/ansible

> 
> Thanks,
> 
> Moshe
> 



-- 
Best regards,
 Paul  mailto:pmis...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


how can i get the source code of goagent.exe?

2014-07-02 Thread 水静流深
There is a open source project-goagent,when you download it and extract it,
code.google.com/p/goagent/downloads‍

 in the local diretory, a file named goagent.exe in it.

how can i get the source code of goagent.exe ,not the binary form ,the text 
form.-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Success with subprocess communicate on Windows?

2014-07-02 Thread Terry Reedy

On 7/2/2014 1:37 PM, Wolfgang Maier wrote:

On 02.07.2014 19:31, Wolfgang Maier wrote:


I am not 100% sure whether that is the problem, but from what I gather
from the subprocess module docs the args string is passed to the Windows
CreateProcess function as a single string.
To me this seems to imply that it is passed as the lpCommandLine
parameter (with Null for the lpApplicationName parameter).
This is what Microsoft says about this case
(http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx):




If lpApplicationName is NULL, the first white space–delimited token of
the command line specifies the module name. If you are using a long file
name that contains a space, use quoted strings to indicate where the
file name ends and the arguments begin (see the explanation for the
lpApplicationName parameter). If the file name does not contain an
extension, .exe is appended. Therefore, if the file name extension is
.com, this parameter must include the .com extension. If the file name
ends in a period (.) with no extension, or if the file name contains a
path, .exe is not appended. If the file name does not contain a
directory path, the system searches for the executable file in the
following sequence.


So in your case the default behavior would be to add an .exe extension
to pyflakes, which is probably not what you intended ?

Best,
Wolfgang



Ah, I forgot about your pyflakes -h example, which works, so my
explanation must be wrong.


I appreciate the attempt. I hope there is someone who has been 
successful who can answer ;-).


--
Terry Jan Reedy


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


Re: how can i get the source code of goagent.exe?

2014-07-02 Thread Terry Reedy

On 7/2/2014 6:40 PM, 水静流深 wrote:

There is a open source project-goagent,when you download it and extract it,
code.google.com/p/*goagent*/downloads‍

  in the local diretory, a file named goagent.exe in it.

how can i get the source code of goagent.exe ,not the binary form ,the
text form.


This appears to be off-topic for this list because I suspect 'goagent' 
meant 'go agent', where 'go' is googles language, not Python.  However, 
go to https://code.google.com/p/goagent/source/checkout. Use g. search 
to fint out about git.



--
Terry Jan Reedy


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


Re: Success with subprocess communicate on Windows?

2014-07-02 Thread Wolfgang Maier
Terry Reedy  udel.edu> writes:

> 
> On 7/2/2014 12:33 AM, Tim Roberts wrote:
> > Terry Reedy  udel.edu> wrote:
> >>
> > You need to use
> >  s.check_output("pyflakes c:\\programs\\python34\\lib\\turtle.py")
> > or
> >  s.check_output(r"pyflakes c:\programs\python34\lib\turtle.py")
> 
> Now I get "Command 'pyflakes c:\programs\python34\lib\turtle.py' returns 
> non-zero exit status 1" on both. On Idle, as least, a command-prompt 
> window is flashed/displayed. It makes no sense to me that in the command 
> interpreter,
> 'pyflakes c:\\programs\\python34\\lib' works and
> 'pyflakes c:\\programs\\python34\\lib\\turtle.py' returns status 1.
> whereas both (with quotes elided and undoubled \) work at the command 
> prompt.
> 

Finally found out what the problem is:
When I'm running your command using the cmd console, I get this output:

c:\python34\lib\turtle.py:571: local variable 'rgb' is assigned to but never
used
c:\python34\lib\turtle.py:2936: local variable 'a21' is assigned to but
never used
c:\python34\lib\turtle.py:3590: local variable 'dummy' is assigned to but
never used
c:\python34\lib\turtle.py:3786: undefined name 'mainloop'
c:\python34\lib\turtle.py:3969: undefined name 'mainloop'
c:\python34\lib\turtle.py:3973: undefined name 'isdown'
c:\python34\lib\turtle.py:3974: undefined name 'pu'
c:\python34\lib\turtle.py:3976: undefined name 'pd'
..

now look at the exit code:
echo %errorlevel%
1

ah, pyflakes does exit with a non-zero exit code when it finds errors in
your file!!

Now, using subprocess.check_output in IDLE:

>>> msg=subprocess.check_output(r'pyflakes c:\python34\lib\turtle.py')
Traceback (most recent call last):
  File "", line 1, in 
msg=subprocess.check_output(r'pyflakes c:\python34\lib\turtle.py')
  File "C:\Python34\lib\subprocess.py", line 618, in check_output
raise CalledProcessError(retcode, process.args, output=output)
subprocess.CalledProcessError: Command 'pyflakes c:\python34\lib\turtle.py'
returned non-zero exit status 1

as you said, but logical since (taken from the docs):

"subprocess.check_output(args, *, input=None, stdin=None, stderr=None,
shell=False, universal_newlines=False, timeout=None) 
Run command with arguments and return its output.

If the return code was non-zero it raises a CalledProcessError. The
CalledProcessError object will have the return code in the returncode
attribute and any output in the output attribute."

and in fact:
>>> try:
msg=subprocess.check_output(r'pyflakes c:\python34\lib\turtle.py')
except subprocess.CalledProcessError as e:
print (e.output[:81])


b"c:\\python34\\lib\\turtle.py:571: local variable 'rgb' is assigned to but
never used"

So, everything's just fine except that it may be more convenient to use
Popen().communicate() to avoid raising the error in the first place :)

Hope it helps this time,
Wolfgang

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


RE: install software via Python script

2014-07-02 Thread Moshe Avraham
 

HI Guys,

I need to install variety of software (Oracle, SqlServer, upgrade JAVA
version, WAS, WMB, Tomcat, etc.) on both WINDOWS and UNIX/LINUX.

These are usual daily operation of large IT departments.

So instead of developing both shell & DOS scripts, I like to develop a
single Python script (for each of these software) to run on all operation
systems.

Can someone suggest an easy simple way of developing a script for Oracle (as
an example).

Thanks,

Moshe

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


Re: 1-0.95

2014-07-02 Thread Chris Angelico
On Thu, Jul 3, 2014 at 6:00 AM, Marko Rauhamaa  wrote:
> Steven D'Aprano :
>
>>>>>> Rational(2).sqrt() * Rational(2).sqrt() == Rational(2)
>>>False
>>
>> Square root of 2 is not a rational number.
>
> Nobody said it was. It's just that even "arbitrary-precision" rational
> numbers wouldn't free you from the issues of floating-point numbers. The
> Decimal number class won't do it, either, of course.

They do free you from the issues of floating point. In exchange, they
give you the problems of rationals. (Most notably, addition becomes
very slow. Remember grade school and learning to add/subtract vulgar
fractions?)

> On the other hand, floating-point numbers are perfect whenever you deal
> with science and measurement. And when you deal with business (= money),
> integers are the obvious choice.

Why are floats perfect for science, but not for other situations?

Integers are great if you can guarantee you can fit within them -
which, when you're talking about money, presumably means you're
working in a fixed-point system (eg with the popular
something-and-cents notation (including the GBP with pounds and
pence), you store currency in cents, which is fixed-point two places
after the decimal). What about when you have to work with fractions of
a cent? Ah! I know! Let's have two integers - one for the number of
dollars/euro/pounds/etc, and then another one that says how much out
of 2**32 of another one we have!

book = (29, 2147483648) # $29.50
airfare = (2468, 2920577761) # $2468.68
interest = (1, 616212701) # $1.1434732

See, integers are the obvious choice for money!

> I would venture to say that the real applications for Decimal are very
> rare. In practice, I'm afraid, people with rather a weak understanding
> of numbers and computation might gravitate toward Decimal unnecessarily.

Your second part? Possibly. There was some discussion about an import
hook that would turn all unmarked non-integer literals into Decimals
rather than floats, and it was decided that it wouldn't be worth it.
But there definitely are real uses for Decimal, and quite a lot of
them - just as there were very solid reasons for REXX's numeric
implementation having been fairly similar. (Although - unsurprisingly
given that Python has had another couple of decades of development -
not as sophisticated. For instance, REXX doesn't have numeric
contexts, so all changes to precision etc are global.)

Numbers can't be represented in a computer in any way that doesn't
potentially demand infinite storage. There are two basic techniques
for storing numbers: ratios, possibly where the denominator is
selected from a very restricted set (IEEE floating point is (usually)
this - the denominator must be a power of two), and algebraic symbols,
where you represent sqrt(2) as "\u221a2" and evaluate to an actual
number only at the very end, if ever (which gets around the problems
of intermediate rounding, and allows perfect cancelling out -
pow("\u221a2",8) == "16"). No matter what system you use, you're
eventually going to get down to a choice: retain all the precision you
possibly can, and maybe use infinite or near-infinite storage; or
throw away the bits that aren't going to affect the calculation
significantly, and keep the object size down to something reasonable.
I do seem to recall, back in maths class, being allowed to use either
22/7 or 3.14 for π, because the difference between either of those and
the true value was not significant :) It's the same in computing,
except that it's common to go as far as 3.141592653589793 (a number I
memorized out of the GW-BASIC manual, back when I first started
programming with floating point). Short of actually running on a
Turing machine, your program is always going to be bound by these
restrictions.

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


Re: Success with subprocess communicate on Windows?

2014-07-02 Thread Ethan Furman

On 07/02/2014 04:22 PM, Wolfgang Maier wrote:


So, everything's just fine except that it may be more convenient to use
Popen().communicate() to avoid raising the error in the first place :)


Nice sleuthing!  :)

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


Is pip being automatically installed for Python 3.4.0?

2014-07-02 Thread Conrad Taylor
Hi, shouldn't pip be automatically installed for Python 3.4.0 release?  I have 
read through the release and the PEP 453.  Thus, can someone confirm whether or 
not this is the case?  BTW, I have installed Python 3.4.0 using MacPorts.

--

Think different and code well,

-Conrad

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


Re: general module auditing

2014-07-02 Thread Rita
On Wed, Jul 2, 2014 at 2:46 PM, Irmen de Jong 
wrote:

> On 2-7-2014 4:04, Rita wrote:
> > yes, this helps. But I want to know who uses the module, serpent. So,
> when
> > I upgrade it or remove it they won't be affected adversely.
>
>
> (Please don't top-post, it makes the discussion harder to follow.)
>
>
> > On Tue, Jul 1, 2014 at 2:16 PM, Irmen de Jong 
> > wrote:
> >
> >> On 1-7-2014 12:38, Rita wrote:
> >>> i work in a group of developers (15 or so)  who are located globally. I
> >>> would like to know what modules everyone is uses if I ever have to
> >> upgrade
> >>> my python. Is there mechanism which will let me see who is using what?
> >>>
> >>> ie,
> >>>
> >>> tom,matplotlib
> >>> bob, pylab
> >>> nancy, numpy
> >>> nancy, matplotlib
> >>>
> >>> etc...
> >>>
> >>>
> >>
> >> Well, if your group is all using Pip (and perhaps even virtualenv), you
> >> could use pip
> >> list. In my case:
> >>
> >> $ pip list
>
> [...]
>
>
> Why would the fact that you upgrade or remove a package, affect another
> developer in
> your group? Are you all using the same machine to develop on, with one
> Python installation?
>
> I think you'll have to tell us some more details about the way you work
> together before
> we can give a meaningful answer to your question.
>
>
> Irmen
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

we have a shared mount point which has our python install. we have 3
servers on one part of the campus  and 2 in another part.

I want to find out what packages our user base is using thats the final
goal. I can figure out who is using python by writing a wrapper but not
what module.



-- 
--- Get your facts first, then you can distort them as you please.--
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is pip being automatically installed for Python 3.4.0?

2014-07-02 Thread Frank Liou
it's truth

pip will be automatically install Python3.4.0

if you want to use another version

you should use wget 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How can I catch values from other def by flask???

2014-07-02 Thread Frank Liou
Steven Thank you!!!

it's work

i'm so appreciate that

hava a nice day^^
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 1-0.95

2014-07-02 Thread Steven D'Aprano
On Wed, 02 Jul 2014 23:00:15 +0300, Marko Rauhamaa wrote:

> Steven D'Aprano :
> 
>>>>>> Rational(2).sqrt() * Rational(2).sqrt() == Rational(2)
>>>False
>>
>> Square root of 2 is not a rational number.
> 
> Nobody said it was. 

Your comment can be read as implying it. You stated:

[quote]
Even "arbitrary-precision" RATIONALS [emphasis added] would 
suffer from the same problem 
[end quote]

and then showed an invented example where you squared a NON-RATIONAL. By 
the way, there's no need to use an invented example. Here is an actual 
example:

py> import math
py> from fractions import Fraction
py> math.sqrt(Fraction(2))**2
2.0004


> It's just that even "arbitrary-precision" rational
> numbers wouldn't free you from the issues of floating-point numbers.

Hmmm, well, I wouldn't put it that way. I would put it that a rational 
number class has problems of its own. A correct, non-buggy rational 
number class does not suffer from most of the problems of floating point 
numbers. For example, apart from x = 0, the following:

1/(1/x) == x

is always true in mathematics, and always true with a rational class, but 
not always true with floating point:

py> x = 49.0
py> 1/(1/x) == x
False

py> x = Fraction(49)
py> 1/(1/x) == x
True


The specific problem you show, with sqrt, comes about because it takes 
you outside of the rationals and into the floating point numbers.


> The Decimal number class won't do it, either, of course.

Decimals are floating point number, so they suffer from the same kind of 
failures as other floating point numbers.


> On the other hand, floating-point numbers are perfect whenever you deal
> with science and measurement. 

/head-desk

I'm sorry Marko, have you not being paying attention? Have you ever done 
any numeric programming? Floating-point is *hard*, not "perfect". Even 
*trivially simple* arithmetic problems can burn you, badly. Have you not 
heard of catastrophic cancellation, or the Table Maker's Dilemma, or ill-
conditioned equations? If scientists don't have to worry about these 
things (and they actually do), it's because the people writing the 
scientific libraries have worried about them.

Almost every thing that most non-experts believe is true about doing 
calculations on a computer is false -- including, I daresay, me. I'm sure 
I've probably got some wrong ideas too. Or at least incomplete ones.

This page gives some examples:

http://introcs.cs.princeton.edu/java/91float/

including a calculation of the harmonic sum 1/1 + 1/2 + 1/3 + 1/4 + ... 
Mathematically that sum diverges to infinity; numerically, it converges 
to a fixed, finite value.


> And when you deal with business (= money),
> integers are the obvious choice.

Unfortunately there is nothing obvious about using integers. If you want 
to represent $1.01, what could be more obvious than using 1.01? But 
that's the *wrong solution*.

Unfortunately using integers for money is trickier than you may think. If 
all you're doing is multiplying, adding and subtracting, then using 101 
for $1.01 is fine. But as soon as you start doing division, percentages, 
sales tax calculations, interest calculations, currency conversions, 
etc., you've got a problem. How do you divide 107 cents by 3? If you just 
truncate:

py> (107//3)*3
105

you've just lost two cents. If you round to the nearest whole number:

py> (round(107/3))*3
108

you've just invented a cent from thin air. Both answers are wrong. 
Depending on your application, you may pick one or the other, but either 
way, you have to care about rounding, and that's neither obvious nor easy.


> I would venture to say that the real applications for Decimal are very
> rare. In practice, I'm afraid, people with rather a weak understanding
> of numbers and computation might gravitate toward Decimal unnecessarily.

Financial applications are one of the real applications for Decimal. You 
can think of Decimal numbers as an easy way to fake the use of integers, 
without having to worry about moving the decimal point around or come up 
with your own rounding modes.

py> from decimal import *
py> setcontext(Context(prec=3))
py> (Decimal("1.07")/3)*3
Decimal('1.07')


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


Re: how can i get the source code of goagent.exe?

2014-07-02 Thread liuerfire Wang
Hi 水静流深
the source code is on https://github.com/goagent/goagent

Hi Terry,
GoAgent, a tool to help cross the GFW, is written by Python not Go. So this
may be not off-topic. :P


On Thu, Jul 3, 2014 at 6:40 AM, 水静流深 <1248283...@qq.com> wrote:

> There is a open source project-goagent,when you download it and extract it,
> code.google.com/p/*goagent*/downloads‍
>
>  in the local diretory, a file named goagent.exe in it.
>
> how can i get the source code of goagent.exe ,not the binary form ,the
> text form.
>
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
>


-- 
Best regards.
/**
google+: +liuerfire  twitter: @liuerfire

蛋疼不蛋疼的都可以试着点一下~^_^~ 
***/
-- 
https://mail.python.org/mailman/listinfo/python-list


TypeError expected in an augmented assignment

2014-07-02 Thread candide
An hybrid list-tuple concatenation is not allowed

>>> []+(1, 2)
Traceback (most recent call last):  
  
  File "", line 1, in
  
TypeError: can only concatenate list (not "tuple") to list  
  
>>>  



hence I was expecting (*) that the following code raises a TypeError :

>>> x = []  
>>>   
>>> x += (1, 2) 
>>>   
>>> x   
>>>   
[1, 2]  
  
>>>


Any explanation ?


(*) as the docs states, the augmented assignment is supposed to perform the 
concatenation : 
An augmented assignment (...) performs the binary operation specific to the 
type of assignment on the two operands (...)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is pip being automatically installed for Python 3.4.0?

2014-07-02 Thread Conrad Taylor


On Wednesday, July 2, 2014 6:29:53 PM UTC-7, Frank Liou wrote:
> it's truth
> 
> 
> 
> pip will be automatically install Python3.4.0
> 
> 
> 
> if you want to use another version
> 
> 
> 
> you should use wget

This doesn't appear to be the case when installing via MacPorts.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TypeError expected in an augmented assignment

2014-07-02 Thread Terry Reedy

On 7/2/2014 10:39 PM, candide wrote:

An hybrid list-tuple concatenation is not allowed


[]+(1, 2)

Traceback (most recent call last):
   File "", line 1, in 
TypeError: can only concatenate list (not "tuple") to list






hence I was expecting (*) that the following code raises a TypeError :


x = []
x += (1, 2)
x

[1, 2]





Any explanation ?

>>> seq = [1,2]
>>> seq.extend((3,4))
>>> seq+= {5, 6}  # the order of extending is not determined
>>> seq
[1, 2, 3, 4, 5, 6]
>>>

--
Terry Jan Reedy

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


Re: Is pip being automatically installed for Python 3.4.0?

2014-07-02 Thread Terry Reedy

On 7/2/2014 9:12 PM, Conrad Taylor wrote:

Hi, shouldn't pip be automatically installed for Python 3.4.0 release?  I have 
read through the release and the PEP 453.  Thus, can someone confirm whether or 
not this is the case?  BTW, I have installed Python 3.4.0 using MacPorts.


by windows installer

--
Terry Jan Reedy

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


Re: Is pip being automatically installed for Python 3.4.0?

2014-07-02 Thread Zachary Ware
On Wed, Jul 2, 2014 at 9:52 PM, Conrad Taylor  wrote:
> This doesn't appear to be the case when installing via MacPorts.

You may need to run `python3.4 -m ensurepip`.  Add '--help' to learn
about the available options.

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


Re: Success with subprocess communicate on Windows?

2014-07-02 Thread Terry Reedy

On 7/2/2014 7:22 PM, Wolfgang Maier wrote:


Finally found out what the problem is:
When I'm running your command using the cmd console, I get this output:

c:\python34\lib\turtle.py:571: local variable 'rgb' is assigned to but never
used
c:\python34\lib\turtle.py:2936: local variable 'a21' is assigned to but
never used
c:\python34\lib\turtle.py:3590: local variable 'dummy' is assigned to but
never used
c:\python34\lib\turtle.py:3786: undefined name 'mainloop'
c:\python34\lib\turtle.py:3969: undefined name 'mainloop'
c:\python34\lib\turtle.py:3973: undefined name 'isdown'
c:\python34\lib\turtle.py:3974: undefined name 'pu'
c:\python34\lib\turtle.py:3976: undefined name 'pd'
..

now look at the exit code:
echo %errorlevel%
1


I did not know about this.


ah, pyflakes does exit with a non-zero exit code when it finds errors in
your file!!


I guessed that and confirmed it in pyflakes.api.main().

The same is true with >pyflakes c:/programs/python34/lib (path for my 
machine), except that then there is 20 or more times as much output.



Now, using subprocess.check_output in IDLE:


msg=subprocess.check_output(r'pyflakes c:\python34\lib\turtle.py')

Traceback (most recent call last):
   File "", line 1, in 
 msg=subprocess.check_output(r'pyflakes c:\python34\lib\turtle.py')
   File "C:\Python34\lib\subprocess.py", line 618, in check_output
 raise CalledProcessError(retcode, process.args, output=output)
subprocess.CalledProcessError: Command 'pyflakes c:\python34\lib\turtle.py'
returned non-zero exit status 1


Yes, but what puzzled me is that running
subprocess.check_output(r'pyflakes c:\programs\python34\lib')
in the regular interpreter *does* produce output instead of the error 
message. My guess is that it fills up the pipe, so that check_output 
starts reading the pipe long before pyflakes exits with status 1.


Hmm. I tried it again, and I see some but not all of the output I got at 
the command line *and* I see the exit status message. So the subprocess 
must get some of the output but then stop when it sees the exit status. 
 Thanks.



as you said, but logical since (taken from the docs):

"subprocess.check_output(args, *, input=None, stdin=None, stderr=None,
shell=False, universal_newlines=False, timeout=None)
Run command with arguments and return its output.

If the return code was non-zero it raises a CalledProcessError. The
CalledProcessError object will have the return code in the returncode
attribute and any output in the output attribute."

and in fact:

try:

msg=subprocess.check_output(r'pyflakes c:\python34\lib\turtle.py')
except subprocess.CalledProcessError as e:
print (e.output[:81])


b"c:\\python34\\lib\\turtle.py:571: local variable 'rgb' is assigned to but
never used"

So, everything's just fine except that it may be more convenient to use
Popen().communicate() to avoid raising the error in the first place :)


As I believe I said in my first post, that is where we started -- but in 
Idle. I did not realize then that at least some of the problem is 
specific to Idle on Windows and not Python on Windows. It may have 
something to do with running in pythonw.exe



Hope it helps this time,


Yes, it did, to focus my attention. I will see if I can get all of the 
output with communicate in the normal interpreter. Having it work in 
Idle is a different matter, as before it hung indefinitely without 
showing anything with

subprocess.check_output(r'pyflakes c:\programs\python34\lib')
or with the original Popen.communicate.
But I should start experiments in Idle with something that works right 
in the normal interpreter.

---
Doing that, this works on 2.7.7, 3.4.1+, and 3.5.0a
(and would work in posix also).

import subprocess as s
p = s.Popen([r'pyflakes', r'c:\programs\python34\lib\turtle.py'],
stdout=s.PIPE, stderr=s.PIPE)
o,e = p.communicate()
for line in o.decode().splitlines(): print(line)

Next I will reapply the patch that did not work, add a debug print, and 
see how what did not work Windows (but worked on linux) is different 
from the above.


--
Terry Jan Reedy

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


Re: 1-0.95

2014-07-02 Thread Rustom Mody
On Thursday, July 3, 2014 7:49:30 AM UTC+5:30, Steven D'Aprano wrote:
> On Wed, 02 Jul 2014 23:00:15 +0300, Marko Rauhamaa wrote:

> > On the other hand, floating-point numbers are perfect whenever you deal
> > with science and measurement. 

> /head-desk



Just as there are even some esteemed members of this list who think
that c - a is a meaningful operation
  where
c is speed of light
a is speed of an automobile



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


Image Upload with FalconFramework

2014-07-02 Thread Peter Romfeld
Hi,

I am stuck at a simple image upload function, in django i just used:

for feature phones:
file = request.body

iOS with Form:
class ImageForm(forms.Form):
image = forms.FileField() 
form = ImageForm(request.POST, request.FILES)
file = request.FILES['image'].read()

with falcon i tried but not working;
req.stream.read()


Cheers,
Peter

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


Re: Is pip being automatically installed for Python 3.4.0?

2014-07-02 Thread Ned Deily
In article ,
 Conrad Taylor  wrote:
> Hi, shouldn't pip be automatically installed for Python 3.4.0 release?  I 
> have read through the release and the PEP 453.  Thus, can someone confirm 
> whether or not this is the case?  BTW, I have installed Python 3.4.0 using 
> MacPorts.

Like many other third-party package managers, MacPorts has chosen to 
continue to distribute pip as a separate item.  To install it and the 
MacPorts Python 3.4:

sudo port install py34-pip

-- 
 Ned Deily,
 n...@acm.org

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


Re: 1-0.95

2014-07-02 Thread Gregory Ewing

Rustom Mody wrote:

Just as there are even some esteemed members of this list who think
that c - a is a meaningful operation
  where
c is speed of light
a is speed of an automobile


Indeed, it should be (c - a) / (1 - (c*a)/c**2).
Although loss of precision might give you the
right answer anyway. :-)

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


Re: 1-0.95

2014-07-02 Thread Rustom Mody
On Thursday, July 3, 2014 10:25:17 AM UTC+5:30, Gregory Ewing wrote:
> Rustom Mody wrote:
> > Just as there are even some esteemed members of this list who think
> > that c - a is a meaningful operation
> >   where
> > c is speed of light
> > a is speed of an automobile

> Indeed, it should be (c - a) / (1 - (c*a)/c**2).
> Although loss of precision might give you the
> right answer anyway. :-)

:-)

Surprising how unfamiliar familiar equations like the Lorentz
transformation look when converted from its usual mathematicerese and
put into programmerese

I like to think unicode would help.
But I find it does not help much:

(c-a)/(1 - ca/c²)

[And I would have sworn there should be a √ somewhere?
Dont remember any of this…]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 1-0.95

2014-07-02 Thread Ian Kelly
On Wed, Jul 2, 2014 at 10:55 PM, Gregory Ewing
 wrote:
> Although loss of precision might give you the
> right answer anyway. :-)

There aren't that many digits in the speed of light.  Unless we're
talking about a very, very slow-moving automobile.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how can i get the source code of goagent.exe?

2014-07-02 Thread Shiyao Ma
Ask on the goagent googlecode?


exe is fow win, dig out more on the linux version. I bet it should be
delivered with py source in that version.


Regards.

2014-07-03 10:20 GMT+08:00 liuerfire Wang :
> Hi 水静流深
> the source code is on https://github.com/goagent/goagent
>
> Hi Terry,
> GoAgent, a tool to help cross the GFW, is written by Python not Go. So this
> may be not off-topic. :P
>
>
> On Thu, Jul 3, 2014 at 6:40 AM, 水静流深 <1248283...@qq.com> wrote:
>>
>> There is a open source project-goagent,when you download it and extract
>> it,
>> code.google.com/p/goagent/downloads‍
>>
>>  in the local diretory, a file named goagent.exe in it.
>>
>> how can i get the source code of goagent.exe ,not the binary form ,the
>> text form.
>>
>>
>>
>>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
>
>
> --
> Best regards.
> /**
> google+: +liuerfire twitter: @liuerfire
> 蛋疼不蛋疼的都可以试着点一下~^_^~
> ***/
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 

吾輩は猫である。ホームーページはhttp://introo.me。
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 1-0.95

2014-07-02 Thread Marko Rauhamaa
Steven D'Aprano :

> On Wed, 02 Jul 2014 23:00:15 +0300, Marko Rauhamaa wrote:
>> Steven D'Aprano :
>>> Rational(2).sqrt() * Rational(2).sqrt() == Rational(2)
False
>>> Square root of 2 is not a rational number.
>> Nobody said it was. 
>
> Your comment can be read as implying it. You stated:
>
> [quote]
> Even "arbitrary-precision" RATIONALS [emphasis added] would 
> suffer from the same problem 
> [end quote]
>
> and then showed an invented example where you squared a NON-RATIONAL.

While √2 is irrational, the hypothetical Rational(2).sqrt() probably
would be another "arbitrary-precision" Rational number and thus,
necessarily an approximation.

That's completely analogous to Decimal(1) / Decimal(3) being an
approximation.

And the point: when dealing with real numbers on a computer, there's no
way to avoid approximations. If an aspiring programmer is dismayed at
the imprecision of 0.1, that probably wouldn't be the right moment to
talk about Decimal().

> By the way, there's no need to use an invented example. Here is an
> actual example:
>
> py> import math
> py> from fractions import Fraction
> py> math.sqrt(Fraction(2))**2
> 2.0004

Sure, although you were invoking "arbitrary-precision" rational numbers,
which Fraction() is not.

> I'm sorry Marko, have you not being paying attention? Have you ever
> done any numeric programming?

Your style is consistent and impeccable.

> Floating-point is *hard*, not "perfect".

It can be both. The point is, regular floating point numbers will likely
the optimal choice for your numeric calculation needs. They are compact,
fast and readily supported by hardware and numeric software. Switching to
Decimal might give you a false sense of security.


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


Re: general module auditing

2014-07-02 Thread Mark Lawrence

On 03/07/2014 02:17, Rita wrote:


On Wed, Jul 2, 2014 at 2:46 PM, Irmen de Jong mailto:irmen.nos...@xs4all.nl>> wrote:

On 2-7-2014 4:04, Rita wrote:
 > yes, this helps. But I want to know who uses the module, serpent.
So, when
 > I upgrade it or remove it they won't be affected adversely.

(Please don't top-post, it makes the discussion harder to follow.)

 > On Tue, Jul 1, 2014 at 2:16 PM, Irmen de Jong
mailto:irmen.nos...@xs4all.nl>>
 > wrote:
 >
 >> On 1-7-2014 12:38, Rita wrote:
 >>> i work in a group of developers (15 or so)  who are located
globally. I
 >>> would like to know what modules everyone is uses if I ever have to
 >> upgrade
 >>> my python. Is there mechanism which will let me see who is
using what?
 >>>
 >>> ie,
 >>>
 >>> tom,matplotlib
 >>> bob, pylab
 >>> nancy, numpy
 >>> nancy, matplotlib
 >>>
 >>> etc...
 >>>
 >>>
 >>
 >> Well, if your group is all using Pip (and perhaps even
virtualenv), you
 >> could use pip
 >> list. In my case:
 >>
 >> $ pip list

[...]


Why would the fact that you upgrade or remove a package, affect
another developer in
your group? Are you all using the same machine to develop on, with
one Python installation?

I think you'll have to tell us some more details about the way you
work together before
we can give a meaningful answer to your question.

Irmen

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

we have a shared mount point which has our python install. we have 3
servers on one part of the campus  and 2 in another part.

I want to find out what packages our user base is using thats the final
goal. I can figure out who is using python by writing a wrapper but not
what module.

--
--- Get your facts first, then you can distort them as you please.--



You can check every users's program for import statements but do you 
really need to, why not check what's in the site-packages folder for 
your python install?


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


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