News:

11 March 2016 - Forum Rules

Main Menu

Python help.

Started by Louhawk, January 07, 2011, 05:30:44 PM

Previous topic - Next topic

Louhawk

I just recently started school for computer programing and my first class is going to be teaching the fundamentals of programing using Python.  At my school, the operating system is Lenix, but at my home, my operating system is Windows xp.  I tired to do some of my homework at home and encountered some problems.  On the school computers, from the Python command promt, I can input commands like "ls" to get a listing of the folder, and "pwd" to print the current directory and "mkdir" to make a new directory.  At home however, those commands don't work, I get a "name is not defined" message. ( I can however assign integers and stuff like that) Is there something I can do to fix this?  Or is this just one of the examples of why programmers prefer Lenix to Windows (so I've been told)?

creeperton

.
#1
.

Mauron

Instead of ls, use dir. mkdir should be the same. I'm not sure about an equivalent of pwd.
Mauron wuz here.

Louhawk

Quote from: creeperton on January 07, 2011, 05:36:33 PM
Lenix?  Do you mean Linux? 

The first thing you should do is tell your professor you're having problems, and what they are.

Come on man, seriously?!?!  Sorry I misspelled Linux, I've never used or typed it before ::)

Quote from: Mauron on January 07, 2011, 05:40:12 PM
Instead of ls, use dir. mkdir should be the same. I'm not sure about an equivalent of pwd.
Thank you for the help, but those did not work.  I had to download and install it on my cpu.  Is it possable I put the program in the wrong place?  I let the cpu decide where to put it.

MathOnNapkins

If the python script you're running are doing stuff like


import os

os.system("ls")


Then it naturally will not work on Windows. If your code is doing something else, then pardon me. It just seems like you can get python running from the command line but that the script itself is failing. Or can you not find python on your Windows system?

SargeSmash

You might also be able to use Cygwin if you want a Linux-style environment in Windows.

For what shall it profit a man, if he shall gain the whole world, and lose his own soul?  -- Mark 8:36

Louhawk

I can get Python running in "command prompt", but I have to type in "PATH C:/Python26;%PATH%" .  After I do this, I can assign variables like x=5, and y=6, (or a = "hello"),then type "print x*y" and it gives me the right answer 30.  But whenever I try to use commands that effect the directory, I am getting a message that says "name is not defined".  I don't see anything that says anything about the os or import os.

golden

When learning a new programming language, the first thing I always do is read the official documentation. Python is very well documented and you should definitely start with the tutorial.

Also, any modern language abstracts the differences between operating systems; this abstraction is provided to you through an API. So Python doesn't care whether you're using Windows or Linux, you just have to find out which method lists files in a folder or which method creates a new folder.

And remember, a good programmer also has to know how to google for this kind of stuff :)

SargeSmash

Quote from: Louhawk on January 07, 2011, 07:07:25 PM
I can get Python running in "command prompt", but I have to type in "PATH C:/Python26;%PATH%" .  After I do this, I can assign variables like x=5, and y=6, (or a = "hello"),then type "print x*y" and it gives me the right answer 30.  But whenever I try to use commands that effect the directory, I am getting a message that says "name is not defined".  I don't see anything that says anything about the os or import os.
That's because the Python shell and the command prompt are two different things.  If you want to use OS commands directly in Python, you have to import the os module and then use os.system('dir').  But you're better off if you're using a directory listing in your script to use os.listdir('directory'), which will return a list of everything in 'directory'.

Hang in there.  It's a somewhat steep learning curve for Python, but I find it much easier to use than most languages.  And there's tons of great documentation, once you get your feet under you, check out http://diveintopython.org/.
For what shall it profit a man, if he shall gain the whole world, and lose his own soul?  -- Mark 8:36

badinsults

Why exactly would you expect Windows and Linux to operate the same way?

I think before doing any programming, you should probably learn some of the fundamental features of your operating systems.  For instance, the difference between Windows shell and BASH (the default shell in most Unix-style operating systems, such as Linux).  if you can't get around the command line on your operating system of choice, learning how to program becomes far more difficult.

creeperton

.
#10
.

badinsults

Hey, I would say Linux is just as easy to use as Windows at this point.  If you are doing any serious programming, I would say there are much better free tools on Linux, which makes life easy.

Garoth Moulinoski

Quote from: badinsults on January 09, 2011, 05:09:26 AM
Hey, I would say Linux is just as easy to use as Windows at this point.  If you are doing any serious programming, I would say there are much better free tools on Linux, which makes life easy.

At least, Ubuntu is plenty easy to use- it's the Linux distro I'm using on both my computers (I wouldn't recommend Puppy only because of how ugly it has looked on my computers). And yeah, it's easy to just go on Ubuntu Software Center, type in "IDE" and get an IDE for some languages (you can get Netbeans and some C/C++ IDEs like this). They even have a developer's section with more options.
Who will quote me next?
Disclaimer: If it sounds wrong, I may have been posting while asleep.