[Tutor] What is wrong with my code?

apometron apometron.listas.cinco at gmail.com
Mon Oct 24 05:21:49 CEST 2011

Sorry to continue discussing my thread on this list, I already subbed on 
the Tutor list
but I need to reply and if possible, some ideas of why it dont works. 
Now it is another
thing, entirely. Rename1.py and Rename2.py works, but why Rename3.py 
dont works?


Thanks by the gentle support.


On 10/23/2011 8:56 PM, Dave Angel wrote:
> On 10/23/2011 06:03 AM, apometron wrote:
>> import os
>> nome = sys.argv[1]
>> final = nome
>> for i in nome:
>>     print i
>>     if nome[i] = "_":
>>         final[i] = " "
>> os.rename(nome, final)
> What do you want to be wrong with it?  There are so many things, it'd 
> be fun to try to see who could come up with the most.
> 1) it's not a valid Fortran program.
> 2) it's missing a shebang line
>     if we assume it's for Windows, or that you run it with an explicit 
> bash line
> 3) if we pretend it's a python program, a few more
> 3a)  It has a syntax error calling the print() function.  (Python 3.2)
>       If we assume it's a python 2.x program
> 4) it uses sys, without importing it
> 5) it uses second argument without checking if the user typed such an 
> argument
> 6) it tries to change a character within a string, which is a 
> non-mutable type
> 7) It creates two more references to the same string sys.argv[1], then 
> tries to modify one of them, not realizing the others would change to.
> 8) it tries to subscript a string using a character.
> 9) it calls rename with two references to the same object.  So nothing 
> will ever actually happen, even if the other problems were fixed.
> Generally, you'll get the best answers here if you specify more of 
> your environment (python version, OS), show what you tried (pasted 
> from the command line), and the results you got (such as stack traces).
> DaveA

More information about the Tutor mailing list