¡@

Home 

python Programming Glossary: os

Directory listing in Python

http://stackoverflow.com/questions/120656/directory-listing-in-python

every file and directory in a directory tree import os for dirname dirnames filenames in os.walk '.' # print path to.. directory tree import os for dirname dirnames filenames in os.walk '.' # print path to all subdirectories first. for subdirname.. all subdirectories first. for subdirname in dirnames print os.path.join dirname subdirname # print path to all filenames...

Python subprocess readlines() hangs

http://stackoverflow.com/questions/12419198/python-subprocess-readlines-hangs

from subprocess import Popen PIPE STDOUT import pty import os file_path ' Users luciano Desktop ruby_sleep.rb' command ' '.join.. command bufsize 0 shell True stdout slave stderr slave close_fds True stdout os.fdopen master 'r' 0 while proc.poll is None.. shell True stdout slave stderr slave close_fds True stdout os.fdopen master 'r' 0 while proc.poll is None data stdout.readline..

How do I execute a program from python? os.system fails due to spaces in path

http://stackoverflow.com/questions/204017/how-do-i-execute-a-program-from-python-os-system-fails-due-to-spaces-in-path

do I execute a program from python os.system fails due to spaces in path I have a python script that.. some reason fails. If I have the following script import os os.system C Temp a b c Notepad.exe raw_input Then it fails with.. reason fails. If I have the following script import os os.system C Temp a b c Notepad.exe raw_input Then it fails with..

How to get file creation & modification date/times in Python?

http://stackoverflow.com/questions/237079/how-to-get-file-creation-modification-date-times-in-python

dates but has to run on Linux Windows. What's the best cross platform way to get file creation modification date times in.. You have a couple of choices. For one you can use the os.path.getmtime and os.path.getctime functions import os.path.. of choices. For one you can use the os.path.getmtime and os.path.getctime functions import os.path time print last modified..

Retrieving python module path

http://stackoverflow.com/questions/247770/retrieving-python-module-path

loaded at least on Mac OS X. So I guess you can do import os path os.path.dirname amodule.__file__ To get the directory to.. at least on Mac OS X. So I guess you can do import os path os.path.dirname amodule.__file__ To get the directory to look for..

Import a module from a relative path

http://stackoverflow.com/questions/279237/import-a-module-from-a-relative-path

in several products and works in many special scenarios like scripts called from another directory or executed with.. execute instead of opening a new interpreter. import os sys inspect # realpath with make your script run even if you.. make your script run even if you symlink it cmd_folder os.path.realpath os.path.abspath os.path.split inspect.getfile..

Ping a site in Python?

http://stackoverflow.com/questions/316866/ping-a-site-in-python

in Python The basic code is from Tkinter import import os sys ana Tk def ping1 os.system 'ping' a Button pen ip 192.168.0.1.. code is from Tkinter import import os sys ana Tk def ping1 os.system 'ping' a Button pen ip 192.168.0.1 a.config text PING.. ping sockets in linux. import ping socket try ping.verbose_ping 'www.google.com' count 3 delay ping.Ping 'www.wikipedia.org'..

How to send Email Attachments with python

http://stackoverflow.com/questions/3362600/how-to-send-email-attachments-with-python

to send an attachment in an email. I know there are other posts online but as a python beginner I find them hard to understand... question Here's another snip from here import smtplib os from email.MIMEMultipart import MIMEMultipart from email.MIMEBase.. send_from send_to subject text files server localhost assert type send_to list assert type files list msg MIMEMultipart..

Search and replace a line in a file in Python

http://stackoverflow.com/questions/39086/search-and-replace-a-line-in-a-file-in-python

from tempfile import mkstemp from shutil import move from os import remove close def replace file_path pattern subst #Create.. mkstemp from shutil import move from os import remove close def replace file_path pattern subst #Create temp file fh abs_path.. in old_file new_file.write line.replace pattern subst #close temp file new_file.close close fh old_file.close #Remove original..

Stop reading process output in Python without hang?

http://stackoverflow.com/questions/4417962/stop-reading-process-output-in-python-without-hang

Python without hang I have a Python program for Linux almost looks like this one import os import time process os.popen.. Python program for Linux almost looks like this one import os import time process os.popen top .readlines time.sleep 1 os.popen.. almost looks like this one import os import time process os.popen top .readlines time.sleep 1 os.popen killall top print..

How to terminate a python subprocess launched with shell=True

http://stackoverflow.com/questions/4789837/how-to-terminate-a-python-subprocess-launched-with-shell-true

the child processes of this group. Here's the code import os import signal import subprocess # The os.setsid is passed in.. the code import os import signal import subprocess # The os.setsid is passed in the argument preexec_fn so # it's run after.. cmd stdout subprocess.PIPE shell True preexec_fn os.setsid os.killpg pro.pid signal.SIGTERM # Send the signal to..

mkdir -p functionality in python

http://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python

this question mkdir p functionality as follows import os errno def mkdir_p path try os.makedirs path except OSError as.. as follows import os errno def mkdir_p path try os.makedirs path except OSError as exc # Python 2.5 if exc.errno.. OSError as exc # Python 2.5 if exc.errno errno.EEXIST and os.path.isdir path pass else raise Update For Python 3.2 os.makedirs..

How do I duplicate sys.stdout to a log file in python?

http://stackoverflow.com/questions/616645/how-do-i-duplicate-sys-stdout-to-a-log-file-in-python

all output goes to the log. Daemon mode works great using os.dup2 . I can't find a way to tee all output to a log in interactive.. 'w' 0 # re open stdout without buffering sys.stdout os.fdopen sys.stdout.fileno 'w' 0 # redirect stdout and stderr.. # redirect stdout and stderr to the log file opened above os.dup2 so.fileno sys.stdout.fileno os.dup2 se.fileno sys.stderr.fileno..

Is there any way to run Python on Android?

http://stackoverflow.com/questions/101754/is-there-any-way-to-run-python-on-android

such as multi touch apps. Kivy runs on Linux Windows OS X Android and iOS. You can run the same python code on all supported.. touch apps. Kivy runs on Linux Windows OS X Android and iOS. You can run the same python code on all supported platforms...

Get last n lines of a file with Python, similar to tail

http://stackoverflow.com/questions/136168/get-last-n-lines-of-a-file-with-python-similar-to-tail

brain calories trying to finesse alignment with physical OS blocks. Using these high level I O packages I doubt you'll see.. see any performance consequence of trying to align on OS block boundaries. If you use lower level I O then you might..

How do I determine if my python shell is executing in 32bit or 64bit mode on OS X?

http://stackoverflow.com/questions/1405913/how-do-i-determine-if-my-python-shell-is-executing-in-32bit-or-64bit-mode-on-os

if my python shell is executing in 32bit or 64bit mode on OS X I need a way to tell what mode the shell is in from within.. the binary is compiled as 64bit though I'm running on OS X 10.6 so it seems to always report 64bit even though I'm using.. are not always reliable particularly in the case of OS X universal binaries . arch x86_64 usr bin python2.6 c 'import..

How to install MySQLdb (Python data access library to MySQL) on Mac OS X?

http://stackoverflow.com/questions/1448429/how-to-install-mysqldb-python-data-access-library-to-mysql-on-mac-os-x

install MySQLdb Python data access library to MySQL on Mac OS X I'm a Python newbie but I've just spent a day working out.. So the question is how to get MySQLdb working on Mac OS X python mysql osx share improve this question Here is.. says here that one of the most pernicious problems is that OS X comes installed with a 32 bit version of Python but most average..

Python - How do I pass a string into subprocess.Popen (using the stdin argument)?

http://stackoverflow.com/questions/163542/python-how-do-i-pass-a-string-into-subprocess-popen-using-the-stdin-argument

or stderr.read to avoid deadlocks due to any of the other OS pipe buffers filling up and blocking the child process. So your..

how to print number with commas as thousands separators in Python 2.x

http://stackoverflow.com/questions/1823058/how-to-print-number-with-commas-as-thousands-separators-in-python-2-x

How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions

http://stackoverflow.com/questions/2088569/how-do-i-force-python-to-be-32-bit-on-snow-leopard-and-other-32-bit-64-bit-quest

module the sys module also has a few simple helpers On Mac OS X you can run a fat binary with your chosen architecture with..

Retrieving python module path

http://stackoverflow.com/questions/247770/retrieving-python-module-path

the path to the .pyc file that was loaded at least on Mac OS X. So I guess you can do import os path os.path.dirname amodule.__file__..

How do I get the path of the current executed file in python?

http://stackoverflow.com/questions/2632199/how-do-i-get-the-path-of-the-current-executed-file-in-python

run from IDLE with execute there is no __file__ attribute OS X 10.6 where I get NameError global name '__file__' is not defined..

How to get current CPU and RAM usage in Python?

http://stackoverflow.com/questions/276052/how-to-get-current-cpu-and-ram-usage-in-python

top and Windows task manager. It currently supports Linux OS X FreeBSD and Windows with Python versions from 2.4 to 3.1 by..

An executable Python app [closed]

http://stackoverflow.com/questions/2933/an-executable-python-app

Python variable scope question

http://stackoverflow.com/questions/370357/python-variable-scope-question

code works as expected in both python 2.5 and 3.0 on OS X if that matters a b c 1 2 3 print a b c def test print a print..

Monitoring files/directories with python [duplicate]

http://stackoverflow.com/questions/597903/monitoring-files-directories-with-python

be best to build a module yourself that works on either OS that uses one of the 2 above methods after detecting what OS..

Why is reading lines from stdin much slower in C++ than Python?

http://stackoverflow.com/questions/9371238/why-is-reading-lines-from-stdin-much-slower-in-c-than-python

in advance Edit I should note that I tried this both under OS X 10.6.8 and Linux 2.6.32 RHEL 6.2 . The former is a macbook..

How to install MySQLdb on Mountain Lion

http://stackoverflow.com/questions/11787012/how-to-install-mysqldb-on-mountain-lion

intel 2.7 clang fno strict aliasing fno common dynamic g Os pipe fno common fno strict aliasing fwrapv mno fused madd DENABLE_DTRACE.. Wall Wstrict prototypes Wshorten 64 to 32 DNDEBUG g Os Wall Wstrict prototypes DENABLE_DTRACE pipe Dversion_info 1.. c _mysql.c o build temp.macosx 10.8 intel 2.7 _mysql.o Os g fno common fno strict aliasing arch x86_64 unable to execute..

cc1: error: unrecognized command line option “-Wno-null-conversion” within installing python-mysql on mac 10.7.5

http://stackoverflow.com/questions/16127493/cc1-error-unrecognized-command-line-option-wno-null-conversion-within-insta

llvm gcc 4.2 fno strict aliasing fno common dynamic g Os pipe fno common fno strict aliasing fwrapv mno fused madd DENABLE_DTRACE.. Wall Wstrict prototypes Wshorten 64 to 32 DNDEBUG g fwrapv Os Wall Wstrict prototypes DENABLE_DTRACE pipe Dversion_info 1.. temp.macosx 10.7 intel 2.7 _mysql.o Wno null conversion Os g fno strict aliasing arch x86_64 cc1 error unrecognized command..

Make distutils look for numpy header files in the correct place

http://stackoverflow.com/questions/2379898/make-distutils-look-for-numpy-header-files-in-the-correct-place

no cpp precomp mno fused madd fno common dynamic DNDEBUG g Os Wall Wstrict prototypes DMACOSX I usr include ffi DENABLE_DTRACE..

Python: MySQLdb and “Library not loaded: libmysqlclient.16.dylib”

http://stackoverflow.com/questions/4559699/python-mysqldb-and-library-not-loaded-libmysqlclient-16-dylib

fno strict aliasing fno common dynamic DNDEBUG g fwrapv Os Wall Wstrict prototypes DENABLE_DTRACE pipe Dversion_info 1.. c _mysql.c o build temp.macosx 10.6 universal 2.6 _mysql.o Os g fno common fno strict aliasing arch x86_64 In file included..

Installing PIL on OS X Snow Leopard w/Xcode4 (no PPC support)

http://stackoverflow.com/questions/5366882/installing-pil-on-os-x-snow-leopard-w-xcode4-no-ppc-support

fno strict aliasing fno common dynamic DNDEBUG g fwrapv Os Wall Wstrict prototypes DENABLE_DTRACE arch i386 arch ppc arch..

Cannot install psycopg2 on OSX 10.6.7 with XCode4

http://stackoverflow.com/questions/5427157/cannot-install-psycopg2-on-osx-10-6-7-with-xcode4

fno strict aliasing fno common dynamic DNDEBUG g fwrapv Os Wall Wstrict prototypes DENABLE_DTRACE arch i386 arch ppc arch..

Memory errors and list limits in python

http://stackoverflow.com/questions/5537618/memory-errors-and-list-limits-in-python

scientific lab Bi xenon 6 cores 12threads each 12GB memory Os win64 Traceback most recent call last File my_file.py line 247..

Trouble Setting Up MySQLdb Module

http://stackoverflow.com/questions/5671480/trouble-setting-up-mysqldb-module

fno strict aliasing fno common dynamic DNDEBUG g fwrapv Os Wall Wstrict prototypes DENABLE_DTRACE arch i386 arch ppc arch.. fno strict aliasing fno common dynamic DNDEBUG g fwrapv Os Wall Wstrict prototypes DENABLE_DTRACE arch i386 arch ppc arch..

Extend python/django with c and mod_wsgi with apache

http://stackoverflow.com/questions/6840486/extend-python-django-with-c-and-mod-wsgi-with-apache

config_vars 'CFLAGS' config_vars 'CFLAGS' .replace ' Os ' ' ' config_vars 'OPT' config_vars 'OPT' .replace ' Os ' '.. ' Os ' ' ' config_vars 'OPT' config_vars 'OPT' .replace ' Os ' ' ' That way can get rid of Os options. Whether it is Os or.. 'OPT' .replace ' Os ' ' ' That way can get rid of Os options. Whether it is Os or O will depend on your Python installation...

IOError: [Errno 13] file not accessible with Google AppEngine 1.6.1

http://stackoverflow.com/questions/8799304/ioerror-errno-13-file-not-accessible-with-google-appengine-1-6-1

from this version. I'm using pythonbrew virtualenv Mac Os X 10.6.8 Thanks for your help python google app engine share..