Differences between revisions 128 and 130 (spanning 2 versions)
Revision 128 as of 2009-11-07 00:21:02
Size: 12891
Editor: PaulBoddie
Comment: Moved category notes, removed some explicit links to question pages. Making a new page for the "game of life" question.
Revision 130 as of 2010-02-09 17:11:43
Size: 10331
Editor: PaulBoddie
Comment: Moved question to separate page.
Deletions are marked like this. Additions are marked like this.
Line 21: Line 21:
 * I want to use ElementTree to parse a text object, but the ElementTree.parse function looks like it only takes file objects. I'm doing this all from within Blender, and don't want to touch the filesystem - so is there a way to create a file object from text (to pass to parse) without touching the file system? I'd also like to go the other way, create a text object from an ElementTree object.
Line 41: Line 39:
 * I am new at python, I have python 2.5 and every time i open the shell python resets my moniter to 800x600. How do I keep python from messing with my monitor settings? -Travis
Line 44: Line 44:
Pages containing longer questions should appear in a list below. Pages containing longer questions should appear in this list:
Line 48: Line 48:
These questions will be moved to the [[#AnsweredLongerQuestions|section below]] when they are added to the CategoryAskingForHelpAnswered category (upon being answered, hopefully). These questions will be moved to the [[#AnsweredLongerQuestions|answered longer questions section]] below when they are answered (having been added to the CategoryAskingForHelpAnswered category).
Line 51: Line 51:

 * How can I add or substract two to the last digit of a float? Like 4.9999 should be 5.0001 or 4.9997. The problem is

 {{{
 >>> 4.9999
 4.9999000000000002
 would yield 4.9999000000000000 or 4.9999000000000004 which is not right.
 I could make a str(4.9999), convert each character to an int and work on each character from right
 to left, but there must be a better way.
 this is not what I want as well:
 >>> ( 4.9999 * 10000 + 2 ) / 10000.0
 5.0000999999999998 -> this should be 5.0001
 this makes it somehow :))
 >>> str(( 4.9999 * 10000 + 2 ) / 10000)
 '5.0001'
 }}}

 http://www.python.org/doc/current/library/decimal.html?highlight=round#decimal-faq
Line 114: Line 96:
 I am new at python, I have python 2.5 and every time i open the shell python resets my moniter to 800x600. How do I keep python from messing with my monitor settings? -Travis
Line 132: Line 112:
 * I'm trying to split a string, but without breaking the quotes
 {{{
x = '"a,b", c, d, "e,f,h", "i,j,k"'
re.sub('"([^"]*)"', "\g<1>", x)
-> 'a,b, c, d, e,f,h, i,j,k' # Ok for me

re.sub('"([^"]*)"', "|\g<1>|", x)
-> '|a,b|, c, d, |e,f,h|, |i,j,k|' # To show the separation of the groups, also Ok

re.sub('"([^"]*)"', "\g<1>".replace(",", "|"), x)
-> 'a,b, c, d, e,f,h, i,j,k' # The same result!
-> 'a|b, c, d, e|f|h, i|j|k' # It doesn't suppose to replace all "," with "|" like here?
 }}}

  * No, it is doing what you told it to do. To realize this you must know that arguments are evaluated before they are passed to the functions. But what is the value of "\g<1>".replace(",", "|")? "\g<1>", of course, as there are no commas to replace in "\g<1>". re.sub therefore receives '"([^"]*)"' and "\g<1>" as arguments, which is the exact equivalent of the first call.
Line 151: Line 115:

 * I am new to Python from Java background, I have following structure
 {{{
/root
 /folder1
  Class1.py
  Class2.py
 /folder2
  Class3.py
 }}}

 I am in the folder2 and want to run class3.py but it need to import a module from Class1.py
 Could someone please help me?

   * I believe you just need to add folder1 to your path variable. Should be something along the lines of...
   {{{#!python
import sys
sys.path.append('/root/folder1')
import Class1
   }}}

   If that doesn't work, look through the documentation for info on how the sys.path variable works -- I may just have the syntax slightly off
Line 181: Line 123:
Pages containing ''answered'' longer questions should appear in a list below. Pages containing ''answered'' longer questions should appear in this list:
Line 185: Line 127:
Questions appear here when they are added to the CategoryAskingForHelpAnswered category. Questions appear here when they are added to the CategoryAskingForHelpAnswered category (having been answered).

Asking for Help

The most efficient way of getting help is via the various mailing lists and newsgroups, particularly the comp.lang.python newsgroup.

See the Community page for a selection of related resources.

For those of you willing to wait, and to add to the archive of problems (and solutions), enter your question in the list below. For longer questions, consider adding a new page using this button...

The page will be automatically added to the longer questions section below.

Questions

  • How (aside from reading gobs and gobs of source code) can I find out the asymptotic time behaviour of various primitive Python operations? For example, for list xs, does xs.append(x) take amortized O(1) time or O(n) time?
  • ssl-1.14.tar.gz exists and supposedly works with Python 2.5x. Assuming I have Visual Studio .NET 2003 available on my box, how do I build the package for Windows. It currently complains about a series of openssl *.h files that aren't available. I can drag in openssl for www.openssl.org, but which version, if that is applicable, and how do I connect the two either in a directory structure or appropriate configuration files?
  • I'm working with embedding Python into my applications. However, the Py_Initialize() is producing an " 'import site' failed " message on non-dev computers. I was wondering if there is a way to fix this or is it just a bug with Python? Thank you.
  • I'm trying to run the IDLE but it wont go on. i have an R52 leptop with ibm-tools installed (there is ver 2.2 there but i changed it so it wont ebe the default one). im trying to run ver 2.6. Thank
  • I'm new to python and I am just working with the idle-shell. How can I write a script without having python executing orders immediately after I type them into the shell? Follow-Up question: Having written the script, how do I run it in the interpreter?
  • I just installed MacPython. Unfortunately it doesn't seem to include the CoreGraphics-Python Module. Where ist my old system python? How can I uninstall MacPython?

  • Is there any way to get the environment from a subprocess.Popen created by python? In other words, if the new process updates it's environment, is it possible to get access to the modifications. For example In my case I'm executing MS Visual Studio's vsvars32.bat file and would like to access the modified PATH environment variable.
  • Is there any way to determine if the C implementation under my Python uses IEEE 754 for floating point numbers? If yes, what is it?
  • I am trying to run Python script in ABAQUS, but there is a error "Import Error: No Module named " Tkinter"". So how can I handle the problem? Thanks
  • Why do I call constructor of Cmd class in my Cmd subclass __init__ method?

  • When I import Tkinter, Python exits. Why?

  • I am new at python, I have python 2.5 and every time i open the shell python resets my moniter to 800x600. How do I keep python from messing with my monitor settings? -Travis

Longer Questions

Pages containing longer questions should appear in this list:

  1. Asking for Help/How delete files in the GUI
  2. Asking for Help/How do you create tables in Python?
  3. Asking for Help/How to solve problem when running python from command line?
  4. Asking for Help/How to use Python with MySQL on Windows
  5. Asking for Help/How to use Reg. Exp. to capture data from random text
  6. Asking for Help/How to utilize SQL Server stored procedure that accepts table valued parameter
  7. Asking for Help/I am trying to run Python on IDLE in Windows. Why doesn't IDLE close old pythonw processes on restarting the shell or even quitting IDLE?
  8. Asking for Help/I want to right-click on data files in Windows XP and open them with a Python program.
  9. Asking for Help/Installation Errors
  10. Asking for Help/Is there a way to use i instead of j for complex numbers?
  11. Asking for Help/Python ISO-8859-1 encoding problem
  12. Asking for Help/Python,Pydev and the terminal in linux.
  13. Asking for Help/What is wrong with this "game of life" program?
  14. Asking for Help/What's the simplest way to connect to a MSSQL database via Python v3? I'm trying sqlite3, but I think I'm barking up the wrong tree...
  15. Asking for Help/Why do I get permission denied errors when using macostools.copy?
  16. Asking for Help/Why do I see b'string' when i print a c_char_p string?
  17. Asking for Help/does a python blink
  18. Asking for Help/exiting idle
  19. Asking for Help/remove escape characters
  20. Asking for Help/remove write protected file forcefully like "rm -f"
  21. Asking for Help/thread started using 'bg' ends without any notification
  22. Asking for Help/with newton force calculator

These questions will be moved to the answered longer questions section below when they are answered (having been added to the CategoryAskingForHelpAnswered category).

Answered (fully or partially)

Answered Longer Questions

Pages containing answered longer questions should appear in this list:

  1. Asking for Help/'break' outside loop
  2. Asking for Help/Can Python introspect like Java?
  3. Asking for Help/Defining rules for adding two different data types.
  4. Asking for Help/Do you need a int main() like you do in c++
  5. Asking for Help/Gui Toolkit for python 3?
  6. Asking for Help/How can "normal" users report bugs in Python or the documentation?
  7. Asking for Help/How can I add or substract two to the last digit of a float?
  8. Asking for Help/How can I convert a hex representation to an integer?
  9. Asking for Help/How can I import a module from a sibling directory?
  10. Asking for Help/How can I run an untrusted Python script safely (i.e. Sandbox)
  11. Asking for Help/How can I split a string, but without breaking the quotes?
  12. Asking for Help/How can i fetch system generated value from database after inserting a row using cursor.execute() function?
  13. Asking for Help/How come when I double click on a .py a black thing flashes and then disappears? And what/where exactly is the 'Python Interpreter'?
  14. Asking for Help/How do I get or set the modification date of a file?
  15. Asking for Help/How do I run Python based software from SourceForge?
  16. Asking for Help/How do I use gzip module with pickle?
  17. Asking for Help/How do I use local variables in methods?
  18. Asking for Help/How do you protect Python source code?
  19. Asking for Help/How does the value from input() become a number, not a string? In 3.2?
  20. Asking for Help/How to have a mutable buffer with python 2.3?
  21. Asking for Help/How to run python from HTML
  22. Asking for Help/How to store information in variable arrays?
  23. Asking for Help/I wish to generate graphics and images directly into a file, but I'm confused as to just what i need to do this with python
  24. Asking for Help/I'm taking an unhandled threading exception that I've been unable to locate
  25. Asking for Help/Is there a way to create a file object from text without touching the file system?
  26. Asking for Help/PythonFramework-x.x.pkg installation fails. Is there a workaround?
  27. Asking for Help/Slow SYBASE query after version upgrade
  28. Asking for Help/Socket module changed in Python 2.5?
  29. Asking for Help/Stop 'Hello World' from flashing
  30. Asking for Help/SubtractionQuestion
  31. Asking for Help/Where can I find a tiny python installation (under 2 MB) for an embedded linux system?
  32. Asking for Help/Why does IDLE refuse to start on Windows?
  33. Asking for Help/Why don't my list and generator comprehensions work?
  34. Asking for Help/Why is my global not assigned?
  35. Asking for Help/Why when I read a text file python reads it as "<built-in method read of _io.TextIOWrapper object at 0x02954558>" and how do I stop this?
  36. Asking for Help/readline under MS
  37. Asking for Help/visual error message
  38. Asking for Help/what and how we can use server in python web development ?

Questions appear here when they are added to the CategoryAskingForHelpAnswered category (having been answered).


CategoryFaq

Asking for Help (last edited 2019-11-04 14:47:35 by ChrisM)

Unable to edit the page? See the FrontPage for instructions.