2to3

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2008
Posts: 402
Reputation: leegeorg07 is an unknown quantity at this point 
Solved Threads: 31
leegeorg07's Avatar
leegeorg07 leegeorg07 is offline Offline
Posting Pro in Training

2to3

 
0
  #1
Apr 16th, 2009
i have python 2.5 and 3 and i want to use 2to3 to convert all of my programs to python3 but i dont know how to use it, if it helps in the Lib folder of python3 it is called lib2to3.

any help or examples welcome.
don't judge me because I'm a year 8!

'it is better to fight for something than to live for nothing'General George S Patton
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 66
Reputation: vidaj is an unknown quantity at this point 
Solved Threads: 14
vidaj vidaj is offline Offline
Junior Poster in Training

Re: 2to3

 
0
  #2
Apr 16th, 2009
open a terminal and go to your code directory.

type in the following:
  1. python path_to_2to3.py yoursourcefile.py

The tool will then output all the changes that it can perform.
If you want to write the changes back to the file, use this command instead
  1. python path_to_2to3.py -w yoursourcefile.py

Take a look at http://docs.python.org/3.0/library/2to3.html for more information
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 402
Reputation: leegeorg07 is an unknown quantity at this point 
Solved Threads: 31
leegeorg07's Avatar
leegeorg07 leegeorg07 is offline Offline
Posting Pro in Training

Re: 2to3

 
0
  #3
Apr 16th, 2009
i tried that in the cmd promt and it said that 'python wasnt a proper command' and im the python command line it said
invalid syntax and pointed to the
  1. yoursourcefile.py

how can i fix this?
don't judge me because I'm a year 8!

'it is better to fight for something than to live for nothing'General George S Patton
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,057
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 266
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is

Re: 2to3

 
0
  #4
Apr 16th, 2009
Originally Posted by leegeorg07 View Post
i tried that in the cmd promt and it said that 'python wasnt a proper command'
You need to use the full path to python.exe if it's not in your PATH variable...

So instead of python path_to_2to3 my_program.py you would need C:\\Python26\\python.exe path_to_2to3 my_program.py
Or which ever version of Python is appropriate. Check your system in case you've installed python in a different directory.
1. Use Code Tags.
2. Homework? Show Effort.
3. Keep discussions on the forum: no PMs
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,613
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 130
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: 2to3

 
0
  #5
Apr 16th, 2009
Another way is to add C:\Python30 (since you don't have Python 2.6) and C:\Python30\Tools\Scripts to your PATH variable.

http://www.brightrev.com/how-to/wind...c.html?start=1

Be careful because if you mess it up some programs may stop working.
Last edited by scru; Apr 16th, 2009 at 11:59 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 402
Reputation: leegeorg07 is an unknown quantity at this point 
Solved Threads: 31
leegeorg07's Avatar
leegeorg07 leegeorg07 is offline Offline
Posting Pro in Training

Re: 2to3

 
0
  #6
Apr 16th, 2009
thanks scru that got rid of the first error but now i have the error of attempted relative import of non package.
  1. from . import item
how can i fix this?
Last edited by leegeorg07; Apr 16th, 2009 at 1:36 pm.
don't judge me because I'm a year 8!

'it is better to fight for something than to live for nothing'General George S Patton
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,057
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 266
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is

Re: 2to3

 
0
  #7
Apr 16th, 2009
Originally Posted by leegeorg07 View Post
thanks scru that got rid of the first error but now i have the error of attempted relative import of non package.
  1. from . import item
how can i fix this?
What is that? Did you write it or is part of 2to3?
1. Use Code Tags.
2. Homework? Show Effort.
3. Keep discussions on the forum: no PMs
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 402
Reputation: leegeorg07 is an unknown quantity at this point 
Solved Threads: 31
leegeorg07's Avatar
leegeorg07 leegeorg07 is offline Offline
Posting Pro in Training

Re: 2to3

 
0
  #8
Apr 16th, 2009
its part of 2to3, its in __main__, this is where it is in the module:
  1. import sys
  2. import os
  3. import logging
  4. import shutil
  5. import optparse
  6.  
  7. from . import refactor
don't judge me because I'm a year 8!

'it is better to fight for something than to live for nothing'General George S Patton
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,057
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 266
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is

Re: 2to3

 
0
  #9
Apr 16th, 2009
Are you using Python30\python.exe or Python25\python.exe to run 2to3? I think 3.0 changed the way imports work so this script probably depends heavily on those changes.
1. Use Code Tags.
2. Homework? Show Effort.
3. Keep discussions on the forum: no PMs
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 402
Reputation: leegeorg07 is an unknown quantity at this point 
Solved Threads: 31
leegeorg07's Avatar
leegeorg07 leegeorg07 is offline Offline
Posting Pro in Training

Re: 2to3

 
0
  #10
Apr 16th, 2009
im using Python30
don't judge me because I'm a year 8!

'it is better to fight for something than to live for nothing'General George S Patton
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC