News: 11 March 2016 - Forum Rules

Author Topic: Python help.  (Read 10545 times)

Louhawk

  • Jr. Member
  • **
  • Posts: 17
    • View Profile
Python help.
« on: January 07, 2011, 05:30:44 pm »
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

  • Hero Member
  • *****
  • Posts: 604
    • View Profile
.
« Reply #1 on: January 07, 2011, 05:36:33 pm »
.
« Last Edit: November 16, 2015, 12:18:28 am by creeperton »

Mauron

  • Submission Reviewer
  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: Python help.
« Reply #2 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.
Mauron wuz here.

Louhawk

  • Jr. Member
  • **
  • Posts: 17
    • View Profile
Re: Python help.
« Reply #3 on: January 07, 2011, 05:50:52 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 ::)

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

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 650
  • Who ya gonna call
    • View Profile
    • Arc-Nova - Rohmackin' and Chiptunin'
Re: Python help.
« Reply #4 on: January 07, 2011, 06:08:55 pm »
If the python script you're running are doing stuff like

Code: [Select]
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

  • Hero Member
  • *****
  • Posts: 3401
    • View Profile
Re: Python help.
« Reply #5 on: January 07, 2011, 06:28:02 pm »
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

  • Jr. Member
  • **
  • Posts: 17
    • View Profile
Re: Python help.
« Reply #6 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.

golden

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • Mare Incognitum
Re: Python help.
« Reply #7 on: January 07, 2011, 08:48:29 pm »
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

  • Hero Member
  • *****
  • Posts: 3401
    • View Profile
Re: Python help.
« Reply #8 on: January 08, 2011, 12:32:02 am »
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

  • Full Member
  • ***
  • Posts: 182
    • View Profile
    • Snes Central
Re: Python help.
« Reply #9 on: January 08, 2011, 05:18:17 am »
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

  • Hero Member
  • *****
  • Posts: 604
    • View Profile
.
« Reply #10 on: January 08, 2011, 01:40:32 pm »
.
« Last Edit: November 16, 2015, 12:18:33 am by creeperton »

badinsults

  • Full Member
  • ***
  • Posts: 182
    • View Profile
    • Snes Central
Re: Python help.
« Reply #11 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.

Garoth Moulinoski

  • Hero Member
  • *****
  • Posts: 6290
  • Disliking that smoke.
    • View Profile
    • My Stuff including Super Smash Karts.
Re: Python help.
« Reply #12 on: January 09, 2011, 12:39:37 pm »
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.