Differences between revisions 93 and 101 (spanning 8 versions)
Revision 93 as of 2008-05-01 01:42:42
Size: 7391
Editor: 124
Comment:
Revision 101 as of 2008-11-15 14:01:24
Size: 8842
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
  See Also: [[Asking for Help/Why doesn`t this work?]]
  * Hi, 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?

  * Hi, 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: import sys; sys.path.append('/root/folder1'); import Class1 (with ; replaced by newlines). 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 5: Line 20:
 * ["I want to right-click on data files in Windows XP and open them with a Python program."]  * [[I want to right-click on data files in Windows XP and open them with a Python program.]]
Line 10: Line 25:
 *["How to store information in variable arrays?"]  *[[How to store information in variable arrays?]]
Line 12: Line 27:
 *["Why do I call conctructor of Cmd class in my Cmd subclass __init__ method?"]  *[[Why do I call conctructor of Cmd class in my Cmd subclass __init__ method?]]
Line 14: Line 29:
 *["How to run Python based softwares from sourceforge? !!!Newbie"]  *[[How to run Python based softwares from sourceforge? !!!Newbie]]
Line 16: Line 31:
 *["How to use Python with MySQL on Windows"]  *[[How to use Python with MySQL on Windows]]
Line 18: Line 33:
 *["How to have a mutable buffer with python 2.3?"]  *[[Why do I get permission denied errors when using macostools.copy]]
Line 20: Line 35:
 *["Why do I get permission denied errors when using macostools.copy"]  *[[When I import Tkinter, Python exits. Why?]]
Line 22: Line 37:
 *["When I import Tkinter, Python exits. Why?"]  *[[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 25: Line 55:
 *[:MultiLineStringsInDocTest:How do I write multi-line strings in doctest tests?]  *[[How to have a mutable buffer with python 2.3?]]
Line 27: Line 57:
 *["How do I get / set the modification date of a file?"]  *[[MultiLineStringsInDocTest|How do I write multi-line strings in doctest tests?]]
Line 29: Line 59:
 *["How do I use gzip module with pickle?"]  *[[How do I get / set the modification date of a file?]]
Line 31: Line 61:
 *["How can "normal" users report bugs in Python or the documentation?"]  *[[How do I use gzip module with pickle?]]
Line 33: Line 63:
 *["How can I convert a hex representation to an integer?"]  *[[How can "normal" users report bugs in Python or the documentation?]]

 *[[
How can I convert a hex representation to an integer?]]
Line 37: Line 69:
 * Related question to the for-a-blink question in the answered section. When running os.system(some command) the CMD.exe window pops up and then terminates when the process terminates. ["How do I get the contents of what was in that CMD.exe window saved someplace - variable, file, etc."] Variable assignment doesn't work - only the exit code is in the variable.  * Related question to the for-a-blink question in the answered section. When running os.system(some command) the CMD.exe window pops up and then terminates when the process terminates. [[How do I get the contents of what was in that CMD.exe window saved someplace - variable, file, etc.]] Variable assignment doesn't work - only the exit code is in the variable.
Line 44: Line 76:
  I would recommend learning Python on a normal desktop system, with a recent version, a full suite of libraries, and [http://ipython.scipy.org/ IPython] (Interactive Python) installed. After you've learned the basics then you can probably adapt more readily to the limitations of the Palm Pilot interface, implementation, version (older), and libraries (reduced subset). ["JimD"]   I would recommend learning Python on a normal desktop system, with a recent version, a full suite of libraries, and [[http://ipython.scipy.org/|IPython]] (Interactive Python) installed. After you've learned the basics then you can probably adapt more readily to the limitations of the Palm Pilot interface, implementation, version (older), and libraries (reduced subset). [[JimD]]
Line 50: Line 82:
 *TestHarnessDesign -- I've been assigned the task of designing a test harness for embedded systems, servers and software. -- ["JimD"]  *TestHarnessDesign -- I've been assigned the task of designing a test harness for embedded systems, servers and software. -- [[JimD]]
Line 53: Line 85:
  See PublishingPythonModules - ["Philip"], 2005-09-19   See PublishingPythonModules - [[Philip]], 2005-09-19
Line 55: Line 87:
  ["lwickjr"]: My question, "my" page. I created that page, empty, in hopes that someone would populate it. They have, and I've read it. They hadn`t yet when I created *this* page for posting how-to questions, at about the same time, so I included the question here in the seed page. See the attachments to [:lwickjr: my page] for my final solution to the problem. ;) By the way, "How to publish Python modules" has been renamed "PublishingPythonModules", to be more Wiki-style. [Me, again.] 2005-11-24.   [[lwickjr]]: My question, "my" page. I created that page, empty, in hopes that someone would populate it. They have, and I've read it. They hadn`t yet when I created *this* page for posting how-to questions, at about the same time, so I included the question here in the seed page. See the attachments to [[lwickjr| my page]] for my final solution to the problem. ;) By the way, "How to publish Python modules" has been renamed "PublishingPythonModules", to be more Wiki-style. [Me, again.] 2005-11-24.
Line 63: Line 95:
  * Father Jack, you should look at the ["PythonHosting"] page and consider some of the options presented there. Your site doesn't seem to be available, so it's hard to assess what its contribution to Python programming knowledge might be. -- PaulBoddie   * Father Jack, you should look at the [[PythonHosting]] page and consider some of the options presented there. Your site doesn't seem to be available, so it's hard to assess what its contribution to Python programming knowledge might be. -- PaulBoddie
Line 67: Line 99:
  * Have you tried using the [http://pyserial.sourceforge.net/pyparallel.html pyParallel] module? -- DavidBoddie   * Have you tried using the [[http://pyserial.sourceforge.net/pyparallel.html|pyParallel]] module? -- DavidBoddie
Line 69: Line 101:
 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 moniter settings? -Travis  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 71: Line 103:
 *["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"]  *[[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]]
Line 73: Line 105:
 *["How can I run an untrusted Python script safely (i.e. Sandbox)"]  *[[How can I run an untrusted Python script safely (i.e. Sandbox)]]
Line 75: Line 107:
 * ["Socket module changed in Python 2.5?"]  * [[Socket module changed in Python 2.5?]]
Line 77: Line 109:
 *[wiki:Self:CanPythonIntrospectLikeJava "I come from a java background. Java has an API that list all classes and their methods that come with Java. Is there anything like that in python?"]  *[[CanPythonIntrospectLikeJava|"I come from a java background. Java has an API that list all classes and their methods that come with Java. Is there anything like that in python?"]]
Line 79: Line 111:
 *[wiki:Self:HowDoYouProtectSource "How can I truly "protect" the python source code we create for a commercial product?"]  *[[HowDoYouProtectSource|"How can I truly "protect" the python source code we create for a commercial product?"]]
Line 81: Line 113:
 *[wiki:Self:DoesTinyPythonExist "Where can I find a tiny python installation (under 2 MB) for an embedded linux system?"]  *[[DoesTinyPythonExist|"Where can I find a tiny python installation (under 2 MB) for an embedded linux system?"]]
Line 83: Line 115:
 * [wiki:Self:LocalVariablesInFunctions "How do I use local variables in a function within a class? (I do not want to use self.x, as this makes the instance have variables. I want variables local to my function, that get destroyed at the end of it.) I can only think of using del at the end of the function, is there a better way?"]  * [[LocalVariablesInFunctions|"How do I use local variables in a function within a class? (I do not want to use self.x, as this makes the instance have variables. I want variables local to my function, that get destroyed at the end of it.) I can only think of using del at the end of the function, is there a better way?"]]
Line 86: Line 118:
 * ["PythonFramework-x.x.pkg installation fails. Is there a workaround?"]  * [[PythonFramework-x.x.pkg installation fails. Is there a workaround?]]
Line 89: Line 122:

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

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

See Also: Asking for Help/Why doesn`t this work?

  • Hi, 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?

  • Hi, 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: import sys; sys.path.append('/root/folder1'); import Class1 (with ; replaced by newlines). 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
  • 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.

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.

Answered (fully or partially)


CategoryFaq

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

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