Change in Python 3.3 with the treatment of sys.argv

C

Colin J. Williams

Below is an extract from some code to run on Python 2.7.3, 3.2.3 and
3.3.0 to compare speeds, both between versions and machines:

if __name__ == '__main__':
# Text string for initial test - Modify for your own machine or
# delete it and and answer the input statement with your own machine
# characteristics.
sys.argv[1:]= ('Intel Pentium D CPU 3.0GHz 1.99 GB of RAM 221GB
Disk Free space', )
main()


def main():
if len(sys.argv) > 1:
idMachine= ' '.join(sys.argv[1:])
...
oFile= open('FP' + now + '.log', 'w')
oFile.writelines(idM + '\n' + sys.version + '\n')

For 2.7, the result is:
Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space
2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)]

for 3.2, the result is:
Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space
3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)]

For 3.3, the result is:
I_n_t_e_l___P_e_n_t_i_u_m___D___C_P_U___3_._0_G_H_z___1_._9_9___G_B___o_f___R_A_M___2_2_1_G_B___D_i_s_k___F_r_e_e___s_p_a_c_e
3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit
(Intel)]

The full test result, for random matrices of increasing order is
available here(http://web.ncf.ca/cjw/FP Summary over 273-323-330.txt)

Colin W.
 
E

Ethan Furman

Below is an extract from some code to run on Python 2.7.3, 3.2.3 and 3.3.0 to compare speeds, both between versions and
machines:

if __name__ == '__main__':
# Text string for initial test - Modify for your own machine or
# delete it and and answer the input statement with your own machine
# characteristics.
sys.argv[1:]= ('Intel Pentium D CPU 3.0GHz 1.99 GB of RAM 221GB Disk Free space', )
main()


def main():
if len(sys.argv) > 1:
idMachine= ' '.join(sys.argv[1:])
...
oFile= open('FP' + now + '.log', 'w')
oFile.writelines(idM + '\n' + sys.version + '\n')

For 2.7, the result is:
Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space
2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)]

for 3.2, the result is:
Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space
3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)]

For 3.3, the result is:
I_n_t_e_l___P_e_n_t_i_u_m___D___C_P_U___3_._0_G_H_z___1_._9_9___G_B___o_f___R_A_M___2_2_1_G_B___D_i_s_k___F_r_e_e___s_p_a_c_e

3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)]

The full test result, for random matrices of increasing order is available
here(http://web.ncf.ca/cjw/FP Summary over 273-323-330.txt)

First, this is what I get with 3.3:

Python 3.3.0 (default, Sep 29 2012, 17:14:58)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
--> import sys
--> sys.argv
['']
--> sys.argv[1:] = ('this is a test!', )
--> sys.argv
['', 'this is a test!']
--> ' '.join(sys.argv[1:])
'this is a test!'


Second, your code doesn't show being joined by an underscore.
 
C

Chris Angelico

Below is an extract from some code to run on Python 2.7.3, 3.2.3 and 3.3.0
to compare speeds, both between versions and machines:

Can you post the actual code in question, please? There are several
problems with the code as posted: main() isn't defined when it gets
called up top, idM vs idMachine, and now isn't defined. I'm guessing
that the difference is somewhere in idM vs idMachine, but that may be
completely off the mark.

ChrisA
 
P

Peter Otten

Colin said:
Below is an extract from some code to run on Python 2.7.3, 3.2.3 and
3.3.0 to compare speeds, both between versions and machines:

if __name__ == '__main__':
# Text string for initial test - Modify for your own machine or
# delete it and and answer the input statement with your own machine
# characteristics.
sys.argv[1:]= ('Intel Pentium D CPU 3.0GHz 1.99 GB of RAM 221GB
Disk Free space', )
main()


def main():
if len(sys.argv) > 1:
idMachine= ' '.join(sys.argv[1:])
...
oFile= open('FP' + now + '.log', 'w')
oFile.writelines(idM + '\n' + sys.version + '\n')

For 2.7, the result is:
Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space
2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)]

for 3.2, the result is:
Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space
3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)]

For 3.3, the result is:
I_n_t_e_l___P_e_n_t_i_u_m___D___C_P_U___3_._0_G_H_z___1_._9_9___G_B___o_f___R_A_M___2_2_1_G_B___D_i_s_k___F_r_e_e___s_p_a_c_e
3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit
(Intel)]

The full test result, for random matrices of increasing order is
available
here(http://web.ncf.ca/cjw/FP Summary over 273-323-330.txt)

You may have run Python 3.3 with a slightly different script, one where you
forgot a trailing comma:
argv = ["foo"]
argv[1:] = ("bar",) # with comma
print("-".join(argv[1:])) bar
argv = ["foo"]
argv[1:] = ("bar") # without comma
print("-".join(argv[1:]))
b-a-r
 
S

Steven D'Aprano

Below is an extract from some code to run on Python 2.7.3, 3.2.3 and
3.3.0 to compare speeds, both between versions and machines:

Do you have an actual question? I don't see the point. You've given us an
"extract", which means the rest of your code could be doing anything, and
the code you have provided doesn't actually run. What question are we
supposed to be answering? Is there a problem here that needs to be solved?

I appreciate the fact that you didn't dump a huge blob of code on us,
truly I do, but please read this page:

http://sscce.org/

for ideas on how to effectively write example code.

By the way, if you suspect a difference in sys.argv, the easiest way to
compare the two is to *look at sys.argv alone*, with as little other
confounding code as possible.

E.g. write this tiny two-line script:

import sys
print(sys.argv)


Then call it from the command line with something like this (tested under
Linux, may be a little different under Windows):


python2.7 myscript.py "hello world" fe fi fo fum
python3.2 myscript.py "hello world" fe fi fo fum
python3.3 myscript.py "hello world" fe fi fo fum


In all three cases, you should get the exact same result:

['hello world', 'fe', 'fi', 'fo', 'fum']


which strongly suggests that whatever problem you are experiencing, it is
not caused by changes in sys.argv. (There is no change in sys.argv, it's
just a list of strings, the same as it always was.)



P.S. it's remarkably, and deceptively, difficult to correctly benchmark
code. The best way is to take your actual application, give it some real
world data to process, and time how long it takes.
 
C

Colin J. Williams

Below is an extract from some code to run on Python 2.7.3, 3.2.3 and
3.3.0 to compare speeds, both between versions and
machines:

if __name__ == '__main__':
# Text string for initial test - Modify for your own machine or
# delete it and and answer the input statement with your own machine
# characteristics.
sys.argv[1:]= ('Intel Pentium D CPU 3.0GHz 1.99 GB of RAM 221GB
Disk Free space', )
main()


def main():
if len(sys.argv) > 1:
idMachine= ' '.join(sys.argv[1:])
...
oFile= open('FP' + now + '.log', 'w')
oFile.writelines(idM + '\n' + sys.version + '\n')

For 2.7, the result is:
Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space
2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)]

for 3.2, the result is:
Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space
3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)]

For 3.3, the result is:
I_n_t_e_l___P_e_n_t_i_u_m___D___C_P_U___3_._0_G_H_z___1_._9_9___G_B___o_f___R_A_M___2_2_1_G_B___D_i_s_k___F_r_e_e___s_p_a_c_e


3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit
(Intel)]

The full test result, for random matrices of increasing order is
available
here(http://web.ncf.ca/cjw/FP Summary over 273-323-330.txt)

First, this is what I get with 3.3:

Python 3.3.0 (default, Sep 29 2012, 17:14:58)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
--> import sys
--> sys.argv
['']
--> sys.argv[1:] = ('this is a test!', )
--> sys.argv
['', 'this is a test!']
--> ' '.join(sys.argv[1:])
'this is a test!'


Second, your code doesn't show being joined by an underscore.

No, the same program ran against each of the three versions. I assume
that 3.3 behaves differently.

Colin W.
 
C

Colin J. Williams

Below is an extract from some code to run on Python 2.7.3, 3.2.3 and
3.3.0 to compare speeds, both between versions and
machines:

if __name__ == '__main__':
# Text string for initial test - Modify for your own machine or
# delete it and and answer the input statement with your own machine
# characteristics.
sys.argv[1:]= ('Intel Pentium D CPU 3.0GHz 1.99 GB of RAM 221GB
Disk Free space', )
main()


def main():
if len(sys.argv) > 1:
idMachine= ' '.join(sys.argv[1:])
...
oFile= open('FP' + now + '.log', 'w')
oFile.writelines(idM + '\n' + sys.version + '\n')

For 2.7, the result is:
Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space
2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)]

for 3.2, the result is:
Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space
3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)]

For 3.3, the result is:
I_n_t_e_l___P_e_n_t_i_u_m___D___C_P_U___3_._0_G_H_z___1_._9_9___G_B___o_f___R_A_M___2_2_1_G_B___D_i_s_k___F_r_e_e___s_p_a_c_e


3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit
(Intel)]

The full test result, for random matrices of increasing order is
available
here(http://web.ncf.ca/cjw/FP Summary over 273-323-330.txt)

First, this is what I get with 3.3:

Python 3.3.0 (default, Sep 29 2012, 17:14:58)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
--> import sys
--> sys.argv
['']
--> sys.argv[1:] = ('this is a test!', )
--> sys.argv
['', 'this is a test!']
--> ' '.join(sys.argv[1:])
'this is a test!'


Second, your code doesn't show being joined by an underscore.

No, the same program ran against each of the three versions. I assume
that 3.3 behaves differently.

Colin W.
 
P

Peter Otten

Colin said:
No, the same program ran against each of the three versions. I assume
that 3.3 behaves differently.

Please show some cooperation -- post actual code that shows the behaviour.
Cut and paste instead of paraphrasing.

Make it as small as you can. In your case that should be easy -- just rip
out the actual benchmark and keep in only the tiny part that processes and
prints sys.argv.
 
C

Colin J. Williams

Below is an extract from some code to run on Python 2.7.3, 3.2.3 and
3.3.0 to compare speeds, both between versions and
machines:

if __name__ == '__main__':
# Text string for initial test - Modify for your own machine or
# delete it and and answer the input statement with your own machine
# characteristics.
sys.argv[1:]= ('Intel Pentium D CPU 3.0GHz 1.99 GB of RAM 221GB
Disk Free space', )
main()


def main():
if len(sys.argv) > 1:
idMachine= ' '.join(sys.argv[1:])
...
oFile= open('FP' + now + '.log', 'w')
oFile.writelines(idM + '\n' + sys.version + '\n')

For 2.7, the result is:
Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space
2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)]

for 3.2, the result is:
Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space
3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)]

For 3.3, the result is:
I_n_t_e_l___P_e_n_t_i_u_m___D___C_P_U___3_._0_G_H_z___1_._9_9___G_B___o_f___R_A_M___2_2_1_G_B___D_i_s_k___F_r_e_e___s_p_a_c_e


3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit
(Intel)]

The full test result, for random matrices of increasing order is
available
here(http://web.ncf.ca/cjw/FP Summary over 273-323-330.txt)

First, this is what I get with 3.3:

Python 3.3.0 (default, Sep 29 2012, 17:14:58)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
--> import sys
--> sys.argv
['']
--> sys.argv[1:] = ('this is a test!', )
--> sys.argv
['', 'this is a test!']
--> ' '.join(sys.argv[1:])
'this is a test!'


Second, your code doesn't show being joined by an underscore.

APOLOGIES to those who responded.

It seems that a change was made in the program between the 3.3 run and
the other runs.

Each produces the same heading now.

Yes, I should have posted the test code. But, in these circumstances,
there is no point in doing that.

Colin W.

Colin W.
 
C

Colin J. Williams

Below is an extract from some code to run on Python 2.7.3, 3.2.3 and
3.3.0 to compare speeds, both between versions and
machines:

if __name__ == '__main__':
# Text string for initial test - Modify for your own machine or
# delete it and and answer the input statement with your own machine
# characteristics.
sys.argv[1:]= ('Intel Pentium D CPU 3.0GHz 1.99 GB of RAM 221GB
Disk Free space', )
main()


def main():
if len(sys.argv) > 1:
idMachine= ' '.join(sys.argv[1:])
...
oFile= open('FP' + now + '.log', 'w')
oFile.writelines(idM + '\n' + sys.version + '\n')

For 2.7, the result is:
Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space
2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)]

for 3.2, the result is:
Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space
3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)]

For 3.3, the result is:
I_n_t_e_l___P_e_n_t_i_u_m___D___C_P_U___3_._0_G_H_z___1_._9_9___G_B___o_f___R_A_M___2_2_1_G_B___D_i_s_k___F_r_e_e___s_p_a_c_e


3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit
(Intel)]

The full test result, for random matrices of increasing order is
available
here(http://web.ncf.ca/cjw/FP Summary over 273-323-330.txt)

First, this is what I get with 3.3:

Python 3.3.0 (default, Sep 29 2012, 17:14:58)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
--> import sys
--> sys.argv
['']
--> sys.argv[1:] = ('this is a test!', )
--> sys.argv
['', 'this is a test!']
--> ' '.join(sys.argv[1:])
'this is a test!'


Second, your code doesn't show being joined by an underscore.

APOLOGIES to those who responded.

It seems that a change was made in the program between the 3.3 run and
the other runs.

Each produces the same heading now.

Yes, I should have posted the test code. But, in these circumstances,
there is no point in doing that.

Colin W.

Colin W.
 
C

Chris Angelico

It seems that a change was made in the program between the 3.3 run and the
other runs.

Each produces the same heading now.

Yep, this is why the simple testcase is so valuable :) Check out
http://sscce.org/ (which Steven also pointed you to) - note the points
made under "Short".

Glad it's solved, anyhow!

ChrisA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top