Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Python frequently asked questions

  • Please log in to reply
4 replies to this topic

#1 v0id



  • Retired Mod
  • PipPipPipPipPipPipPipPip
  • 2313 posts

Posted 05 August 2008 - 11:30 PM

Before posting make sure to read the FAQ, and be sure to follow its rules as well.

This thread is meant as another FAQ which is specialized in this forum, the Python forum, particular, and the language itself. If you read this before creating a thread or a post you may avoid asking already frequently asked questions.

I want to learn Python, what do I do?
Python is an interpreted language. This means that your sourcecode will not be compiled into machine code, like C++ and many other languages, but it will be interpreted by a program: an interpreter. There is many implementations of Python, but the official one is called CPython, and is also simply known as the official Python.
This is the basic tool every Python programmer needs in order to get started programming. Other tools include debuggers for debugging and IDEs for easily management of sourcecode and interpreting.
When you have the tools you need, you only need to learn the language. This can be done in multiple ways. One can learn a lot completely free directly from the internet, and from this knowledge achieved from the internet being able to create beautiful applications. If you however don't mind paying some cash, or need in-depth information, one of the best choices is to get your hands on a book. Books will normally go more into details, than most websites will.
The best choice is to join a programming-class or course. In this way you'll be able to ask your teacher the questions you have on mind, and try out new stuff in a positive environment

Is this tool better than that tool?
This is mostly a matter of taste. Different people prefer different tools: maybe because it's faster; maybe because it's easier to use; maybe because it looks good; etc. So, if you're asking such question you must be prepared to get many different replies, which all states different things.
Investigating and collecting information about different tools is a better solution. In that way you learn about the different tools, and you also find out whether they fit you or not. If you finally end up with two or maybe three tools, and cannot choose, then you can go to the forums and ask us for our opinion. In that way you will get specific replies to the tools you're considering, and not some tools you don't even know about.

You can find a list of tools, books, websites, and other general resources for Python in the Python resource thread.
  • 2
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#2 Chewie


    CC Leader

  • Just Joined
  • PipPipPipPipPipPipPip
  • 1074 posts

Posted 06 August 2008 - 07:05 AM

You yet to let me down v0id!
  • 0

#!CrunchBang Linux ~$ apt-get into it | #!(Statler:R20101205): OpenBox | Like Linux?
“The cure for boredom is curiosity. There is no cure for curiosity.”

#3 Vladimir


    CC Resident

  • Just Joined
  • PipPipPipPip
  • 79 posts

Posted 05 December 2010 - 10:30 AM

How to handle user input using Command Line Interface?
There are two global functions: input() and raw_input. First evaluates input as Python expression and is unsafe. You typically have to use raw_input(). Example:
age = int(raw_input("Please enter your age: ")) # reads user age from prompt and converts it to integer
Must read: 7. Input and Output — Python v2.7.1 documentation

How to handle output to the user using CLI?
There is a built-in function print(). Your first attempt to show user his age may look like this:
print("Your age: " + age) # results in TypeError
This happens because Python does not know how to concatenate str and int:
print("Your age: " + str(age)) # note type conversion from integer to string
But better way is using String formatting:
print("Your age: %d" % age) # code looks cleaner, python automatically handles type conversion
During debugging you can use string formatting to display content of dict, list, etc:
user_1 = {'name': 'Vladimir', 'site': 'forum.codecall.net'}

print 'User_1 name: ' + user_1['name'] # this
print 'User_1 site: ' + user_1['site'] # is ugly

print 'user_1 = %r' % user_1 # nice way

Edited by Vladimir, 05 December 2010 - 12:36 PM.

  • 0

#4 PurityLake


    CC Regular

  • Member
  • PipPipPip
  • 36 posts
  • Location:Ireland
  • Programming Language:C++, Python
  • Learning:C, C++, Lua

Posted 05 March 2013 - 06:57 AM

Using command line arguments/options:

Here is a sample of code that you can use to show that it works,




import sys

args = sys.argv

for idx, val in enumerate(args, start=1):
    print idx, "\t", val 

sys.argv is a list of the arguments that are supplied at run time. Take the following example


python foo.py these are arguments


Would return:


1.    foo.py

2.    these

3.    are

4.    arguments


First thing that you should notice is that the name of the python file is the first element in the list. Everything else is contained after that. So lets say you wanted just the arguments and not the name of the file. You can use something like this.



args = sys.argv[1:]

If you were to use this in the program, the following would be returned


1.    these

2.    are

3.    arguments


Please also note that there is are more advanced modules for taking care of command line arguments such as argpase, optparse and getopt

If you would like me to got into detail on either of those libraries, pm me here

  • 0

#5 Predom


    CC Newcomer

  • Member
  • PipPip
  • 13 posts
  • Location:Italy
  • Learning:PHP, Python

Posted 17 June 2014 - 11:11 PM

Why Python?


Python is a wonderful interpreted language that allow to users to develop many kind of applications such as VideoGame (see 'PyGame'), GUI (see Tkinter or WxPython), Website (see Django web framework) or simple script.

It has got an elegant and compact syntax that allow to users to be ordered.


Begin to learn Python is easier than other languages, you can start with the official site (www.python.org) where you'll find many free tutorials and a list of good books for programmers e non-programmers.


At the moment, Python is used by many famous company (such as Yahoo! and Google) and NASA, too.


It was developed some years ago by Guido van Rossum.


Note: Sorry for my bad english, but I'm italian :|

  • 0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download