Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
in python 2 and python 3
#12
(Feb-13-2017, 04:21 AM)metulburr Wrote:
Quote:the script people download needs to work without them downloading or installing anything else, nor having done so in the past, whether they run it on a recent python 2 or run it on a recent python 3.
the module six, and sys are in the standard library so they wont have to install anything extra either way.

then module six is the way to go.  does anyone know what the earliest version is that six was included in?

(Feb-13-2017, 11:37 AM)ichabod801 Wrote:
(Feb-13-2017, 04:21 AM)metulburr Wrote: he is saying to utilize python3.x where raw_input is no longer defined to determine python version

Well, not exactly. What I meant to say was that in some cases, you don't need sys to determine the version. In that case I had a script that I wanted to work in either 2.x or 3.x, but I wanted to use the 3.x version of input (which is 2.x's raw_input) no matter what. I wasn't suggesting that you use raw_input's existence as a way to test for version if you wanted to do something else across the 2/3 barrier.
if the program is using input() then this can be done.

but what if it isn't

i have not used input() since my first python script (and back then it was module pexpect, not really input()).

write a function that reads a file and counts the number lines in it (an example; use another example, if you prefer).  test the argument, if it is a, or any kind of, string, work with that as the file name (open it), otherwise test if it is, or assume it it, an open file object.  how would you (prefer to) do this (do not install anything, but you can use module six)?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
in python 2 and python 3 - by Skaperen - Feb-12-2017, 04:19 AM
RE: in python 2 and python 3 - by stranac - Feb-12-2017, 06:12 AM
RE: in python 2 and python 3 - by wavic - Feb-12-2017, 07:08 AM
RE: in python 2 and python 3 - by metulburr - Feb-12-2017, 09:08 PM
RE: in python 2 and python 3 - by ichabod801 - Feb-12-2017, 11:55 PM
RE: in python 2 and python 3 - by snippsat - Feb-13-2017, 01:48 AM
RE: in python 2 and python 3 - by Skaperen - Feb-13-2017, 02:45 AM
RE: in python 2 and python 3 - by metulburr - Feb-13-2017, 04:21 AM
RE: in python 2 and python 3 - by Skaperen - Feb-17-2017, 05:10 AM
RE: in python 2 and python 3 - by wavic - Feb-13-2017, 07:56 AM
RE: in python 2 and python 3 - by ichabod801 - Feb-13-2017, 11:37 AM
RE: in python 2 and python 3 - by snippsat - Feb-13-2017, 01:47 PM
RE: in python 2 and python 3 - by ichabod801 - Feb-18-2017, 01:57 AM
RE: in python 2 and python 3 - by Skaperen - Feb-18-2017, 05:16 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020