Python Questions 下载本文

内容发布更新时间 : 2024/11/8 3:17:06星期一 下面是文章的全部内容请认真阅读。

1. Have you ever used Python, for how long?

2. Python can be used on what kinds of OS?

Python runs on Windows, Linux/Unix, Mac OS X, and has been ported to the Java and .NET virtual machines.

3. What’s the versions of Python have you used, what version is the major versions of Python? Python 2.x is the status quo, Python 3.x is the shiny new thing.

At the time of writing (July 4, 2010), the final 2.7 release is out, with a statement of extended support for this end-of-life release. The 2.x branch will see no new major releases after that. Version 3.1 already available and 3.2 due for release around the turn of the year

4. Python is interpreted language or compiled language?

Python is interpreted language, and can be pre-compiled to byte-code.

5. What’s the different between running py and pyc file?

When running \test.py\the interpreter will first pre-compile the test.py source file, and then execute it.

When running \

6. Python is OO or not?

Python is OO (Object Oriented).

7. Function is Object or not in Python?

Everything in Python is Object in Python, include function.

8. What’s module in Python?

A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Within a module, the module’s name (as a string) is available as the value of the global variable __name__.

9. What are packages in Python?

Packages are a way of structuring Python’s module namespace by using “dotted module names”. For example, the module name A.B designates a sub-module named B in a package named A.

10. Python language contains what items and how does it organized? Programs are composed of modules

A module can contain executable statements as well as function definitions. Statements contain expressions

Expressions create and process objects

11. What kind of IDE for Python have you ever used?

Eclipse NetBeans PythonWin Wing IDE Boa Constructor Pydev Eric4 Idle etc

12. What’s Zope?

Zope is an open source web application server primarily written in the Python programming language.

13. What’s Plone

A powerful, flexible Content Management solution that is easy to install, use and extend

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.

14. What’s Twisted Python

A framework for asynchronous network programming.

15. Where to find python applications http://www.python.org/about/success/

16. What’s Standard Data Types in Python Python has five standard data types: Numbers String List Tuple Dictionary

17. How can Python utilize Java and .Net Jython & python.net

18. How to make exe on Windows

For Windows, the simplest way of creating a standalone executable from Python applications is to use the tool Py2Exe

19. What’s comments in Python

There are two styles of comments in python: # Single line comment

\ which spawns many lines \

20. Dose Python support a character type? Python does not support a character type

21. What’s the different between single quotes, double quotes and Triple Quotes? Python treats single quotes the same as double quotes.

Python's triple quotes comes to the rescue by allowing strings to span multiple lines, including verbatim NEWLINEs, TABs, and any other special characters.

The syntax for triple quotes consists of three consecutive single or double quotes.

22. Can Lists, Tuples, and Dictionaries store Lists, Tuples, and Dictionaries as an element? (Data Type Wrap Up)

Lists, Tuples, and Dictionaries can store any type (including other lists, tuples, and dictionaries!) Only lists and dictionaries are mutable All variables are references

23. Give me an example of Python:Hello world #!/usr/bin/env python print \ Or

import sys

sys.stdout.write(\

24. How to get standard input:

Python has two functions designed for accepting data directly from the user: raw_input()

raw_input() asks the user for a string of data (ended with a newline), and simply returns the string. input()

input() uses raw_input to read a string of data, and then attempts to evaluate it as if it were a Python program, and then returns the value that results.

Python includes a built-in file type. Files can be opened by using the file type's constructor: f = file('test.txt', 'r')

This means f is open for reading. The first argument is the filename and the second parameter is the mode, which can be 'r', 'w', or 'rw', among some others.

The most common way to read from a file is simply to iterate over the lines of the file: f = open('test.txt', 'r') for line in f: print line[0] f.close()

25. What’s the different between is and ==?

You should really only use 'is' to check for object identity, and for any kind of value comparison, == is the way to go.

26. How to handle exception in Python? try ... except ... finally / raise

27. What’s List and Tuple, what’s the difference between them?

Both LISTS and TUPLES consist of a number of objects which can be referenced by their position number within the object.

A Tuple is immutable but a list is mutable, so tuple is faster then List.

Built-in Functions

Please introduce some useful functions:

28. abs(x)

Return the absolute value of a number. The argument may be a plain or long integer or a floating point number. If the argument is a complex number, its magnitude is returned.

29. dir([object])

Without arguments, return the list of names in the current local scope. With an argument, attempt to return a list of valid attributes for that object.

30. eval(expression[, globals[, locals]])

The expression argument is parsed and evaluated as a Python expression (technically speaking, a condition list) using the globals and locals dictionaries as global and local namespace.

31. format(value[, format_spec])

Convert a value to a “formatted” representation, as controlled by format_spec.

32. execfile(filename[, globals[, locals]])

This function is similar to the exec statement, but parses a file instead of a string.

Modules for all needs

Please introduce some useful modulers:

Graphical interface wxPython http://wxpython.org Graphical interface pyGtk http://www.pygtk.org

Graphical interface pyQT http://www.riverbankcomputing.co.uk/pyqt/ Graphical interface Pmw http://pmw.sourceforge.net/

Graphical interface Tkinter 3000 http://effbot.org/zone/wck.htm Graphical interface Tix http://tix.sourceforge.net/

Database MySQLdb http://sourceforge.net/projects/mysql-python Database PyGreSQL http://www.pygresql.org/ Database Gadfly http://gadfly.sourceforge.net/ Database SQLAlchemy http://www.sqlalchemy.org/

Database psycopg http://www.initd.org/pub/software/psycopg/ Database kinterbasdb http://kinterbasdb.sourceforge.net/ Database cx_Oracle http://www.cxtools.net/default.aspx?nav=downloads Database pySQLite http://initd.org/tracker/pysqlite

MSN Messenger msnlib http://auriga.wearlab.de/~alb/msnlib/ MSN Messenger pymsn http://telepathy.freedesktop.org/wiki/Pymsn MSN Messenger msnp http://msnp.sourceforge.net/ Network Twisted http://twistedmatrix.com/

Images PIL http://www.pythonware.com/products/pil/

Images gdmodulehttp://newcenturycomputers.net/projects/gdmodule.html Images VideoCapture http://videocapture.sourceforge.net/

Sciences and Maths scipy http://www.scipy.org/ Sciences and Maths NumPy http://numpy.scipy.org//

Sciences and Maths numarray http://www.stsci.edu/resources/software_hardware/numarray Sciences and Maths matplotlib http://matplotlib.sourceforge.net/

Games Pygame http://www.pygame.org/news.html Games Pyglet http://www.pyglet.org/ Games PySoy http://www.pysoy.org/

Games pyOpenGL http://pyopengl.sourceforge.net/

Jabber jabberpy http://jabberpy.sourceforge.net/

Web scrape http://zesty.ca/python/scrape.html Web Beautiful Soup http://crummy.com/software/BeautifulSoup Web pythonweb http://www.pythonweb.org/

Web mechanize http://wwwsearch.sourceforge.net/mechanize/

Localisation geoname.py http://www.zindep.com/blog-zindep/Geoname-python/ Serial port pySerial http://pyserial.sourceforge.net/ Serial port USPP http://ibarona.googlepages.com/uspp

Parallel Port pyParallel http://pyserial.sourceforge.net/pyparallel.html

USB Port pyUSB http://bleyer.org/pyusb/

Windows ctypes http://starship.python.net/crew/theller/ctypes/ Windows pywin32 http://sourceforge.net/projects/pywin32/ Windows pywinauto http://www.openqa.org/pywinauto/ Windows pyrtf http://pyrtf.sourceforge.net/

Windows wmi http://timgolden.me.uk/python/wmi.html PDA/GSM/Mobiles pymo http://www.awaretek.com/pymo.html PDA/GSM/Mobiles pyS60 http://sourceforge.net/projects/pys60

Sound pySoundic http://pysonic.sourceforge.net/ Sound pyMedia http://pymedia.org/ Sound FMOD http://www.fmod.org/

Sound pyMIDI http://www.cs.unc.edu/Research/assist/developer.shtml

GMail libgmail http://libgmail.sourceforge.net/ Google pyGoogle http://pygoogle.sourceforge.net/ Expect pyExpect http://pexpect.sourceforge.net/

WordNet pyWordNet http://osteele.com/projects/pywordnet/

Command line cmd http://blog.doughellmann.com/2008/05/pymotw-cmd.html Compiler backend llvm-py http://mdevan.nfshost.com/llvm-py/ 3D VPython http://vpython.org