sys

Is it possible to write to a python frame object as returned by sys._getframe() from python code running within the interpreter?

Apropos of This question, there is a bit of scaffolding within the interpreter to inspect frame objects, which can be retrieved by sys._getframe(). The frame objects appear to be read only, but I can't find anything obvious in the docs that explicitly states this. Can someone confirm whether these objects are writeable (in some way) or...

delete *.pyc continuation

As a follow-up to this question, I have a new question: What is happening internally in os.remove(module_name) and del sys.modules["module_name"]? I need an urgent help for this.Please help me out. ...

Python's sys.path value

Where is Python's sys.path initialized from? UPD: Python is adding some paths before refering to PYTHONPATH: >>> import sys >>> from pprint import pprint as p >>> p(sys.path) ['', 'C:\\Python25\\lib\\site-packages\\setuptools-0.6c9-py2.5.egg', 'C:\\Python25\\lib\\site-packages\\orbited-0.7.8-py2.5.egg', '...

Python: Why does `sys.exit(msg)` called from a thread not print `msg` to stderr?

Hello! Today I ran against the fact, that sys.exit() called from a child-thread does not kill the main process. I did not know this before, and this is okay, but I needed long time to realize this. It would have saved much much time, if sys.exit(msg) would have printed msg to stderr. But it did not. It turned out that it wasn't a real ...

Cant get __import__() to dynamically import a module in python - I know this cause it doesn't show up in sys.modules

Wrote a small script - just trying to get used to the os, sys, and some other common modules/libraries available to python at install. The gist: The script is designed to search the python directory for all available modules (whether they are installed or not), then it is suppose to check what modules are currently loaded, then it offe...

Python equivalent of PyErr_Print()

What is the Python API equivalent of PyErr_Print(), from the C interface? I'm assuming a call in either the sys, or traceback modules, but can't find any functions therein that make calls to PyErr_Print(). Addendum I'm after the Python call to get the same functionality as PyErr_PrintEx(), described as: Print a standard traceback to ...

why 'setprofile' print this.

import sys def a(): print 'aaa' def profiler(frame, event, arg): print event, frame.f_code.co_name, frame.f_lineno, "->", arg # profiler is activated on the next call, return, or exception sys.setprofile(profiler) a() print call a 5 -> None#what is it aaa return a 6 -> None#what is it return <module> 12 -> None#what is it ...

how to fetch the row count for all the tables in a SQL SERVER database

I was in search of a SQL Script , in order to determine , if there is any data(row count ideally) in any of the tables in a given database. The idea was to re incarnate the database , in case if there are any rows existing(in any of the database) . The database being spoken of is SQLSERVER. Could Someone suggest a sample script.? th...

Problem with sys.argv[1] when unittest module is in a script

Hello, I have a script that does various things and access paramenters using sys.argv but when the script gets to the unittest part of the code it says there is no module for this. The script that I have is: class MyScript(): def __init__(self): self.value = sys.argv[1] def hello(self): print self.value ...

Why is this the output of this python program?

Someone from #python suggested that it's searching for module "herpaderp" and finding all the ones listed as its searching. If this is the case, why doesn't it list every module on my system before raising ImportError? Can someone shed some light on what's happening here? import sys class TempLoader(object): def __init__(sel...

How to poll a file in /sys

Hi, I am stuck reading a file in /sys/ which contains the light intensity in Lux of the ambient light sensor on my Nokia N900 phone. See thread on talk.maemo.org here I tried to use pyinotify to poll the file but this looks some kind of wrong to me since the file is alway "process_IN_OPEN", "process_IN_ACCESS" and "process_IN_CLOSE_NOW...

howto create a filesystem like /proc?

I would like to create a pseudo filesystem like /proc to access an applications configuration. How could i achieve this or where could i find some introductory dokumentation about it? ...

Permanently add a directory to PYTHONPATH

Whenever I use sys.path.append, the new directory will be added. However, once I close python, the list will revert to the previous (default?) values. How do I permanently add a directory to PYTHONPATH? Using Windows. ...

Android: Write to /sys/ directory

I'm developing an application that is not intended to be released as a standard app. It'll be run on a single rooted device. I require the ability to write to a file in the /sys/ directory. The file in question is owned by root and has -rw-rw-rw- permissions. I am aware that there may be restrictions on the VM my code runs within that ...

asp.net 4.0 sys is undefined horror

[edit]: Figured out where it goes wrong. It has something to do with my Routing (note: im not using MVC but webforms). Here's the little piece in my global.asax which causes it: routes.Add( "Home", new Route("{PageIndex}", new p7r.Routing.HomeRouteHandler()) ); Now this is the route for the hom...

Microsoft JScript runtime error: 'Sys' is undefined

Hi, I am having problems with an intermitent error in an ASP.Net Ajax enabled website. The error I am receiving is the old faithful "Microsoft JScript runtime error: 'Sys' is undefined" error. Googling this error usually turns up the suggestion to add the correct "httpHandlers" and "httpModules" into the "web.Config" file. The web.confi...

Python: in what encoding is sys.argv?

In what encoding are the elements of sys.argv, in Python? are they encoded with the sys.getdefaultencoding() encoding? sys.getdefaultencoding(): Return the name of the current default string encoding used by the Unicode implementation. PS: As pointed out in some of the answers, sys.stdin.encoding would indeed be a better guess. I...