How do I check if a file exists using Python?
How do I check if a file exists, using Python. without using a try: statement? ...
How do I check if a file exists, using Python. without using a try: statement? ...
I need to enable/disable completely network interfaces from a script in Windows XP. I'm looking for a python solution, but any general way (eg WMI, some command-line à la netsh, some windows call) is welcome and will be adjusted. Thanks. ...
example: a_list = [1, 2, 3] a_list.len() # doesn't work len(a_list) # works Python being (very) object oriented, I don't understand why the 'len' function isn't inherited by the object. Plus I keep trying the wrong solution since it appears as the logical one to me ...
I wonder why would a C++, C#, Java developer want to learn a dynamic language? Assuming the company won't switch its main development language from C++/C#/Java to a dynamic one what use is there for a dynamic language? What helper tasks can be done by the dynamic languages faster or better after only a few days of learning than with th...
What are come good (or at least clever) ways of running multiple sites from a single, common Python web framework (ie: Pylons, TurboGears, etc)? I know you can do redirection based on the domain or path to rewrite the URI to point at a site-specific location and I've also seen some brutish "if site == 'site1' / elseif / elseif / etc" th...
Which is better to use for timing in Python? time.clock() or time.time()? Which one provides more accuracy? for example: start = time.clock() ... do something elapsed = (time.clock() - start) vs. start = time.time() ... do something elapsed = (time.time() - start) ...
I'd like to search for a given MAC address on my network, all from within a Python script. I already have a map of all the active IP addresses in the network but I cannot figure out how to glean the MAC address. Any ideas? ...
What would be the best way to implement a simple crash / error reporting mechanism? Details: my app is cross-platform (mac/windows/linux) and written in Python, so I just need something that will send me a small amount of text, e.g. just a timestamp and a traceback (which I already generate and show in my error dialog). It would be f...
I am relatively new to Python, and I have always used the standard cpython (v2.5) implementation. I've been wondering about the other implementations though, particularly Jython and IronPython. What makes them better? What makes them worse? What other implementations are there? I guess what I'm looking for is a summary and list of...
How many of you moved from one language to Python and found it more enjoyable and generally more "fun" to code than before? Or maybe you tried Python and thought: "It is not for me, I stay with my C++/Java, Python is too simple/overrated/etc."? I moved from PHP to it(and to Django framework) and I code my projects faster, appreciating ...
I need to get a list of attribute values from child elements in Python. It's easiest to explain with an example. Given some XML like this: <elements> <parent name="CategoryA"> <child value="a1"/> <child value="a2"/> <child value="a3"/> </parent> <parent name="CategoryB"> <child value="b1"/> ...
We are mainting a web application that is built on Classic ASP using VBScript as the primary language. We are in agreement that our backend (framework if you will) is out dated and doesn't provide us with the proper tools to move forward in a quick manner. We have pretty much embraced the current webMVC pattern that is all over the place...
I am trying to call a shell script that sets a bunch of environment variables on our server from a mercurial hook. The shell script gets called fine when a new changegroup comes in, but the environment variables aren't carrying over past the call to the shell script. My hgrc file on the respository looks like this: [hooks] changegroup...
I tend to use SQLite when doing Django development, but on a live server something more robust is often needed (MySQL/PostgreSQL, for example). Invariably, there are other changes to make to the Django settings as well: different logging locations / intensities, media paths, etc. How do you manage all these changes to make deployment a ...
I have a class: class MyClass: def __init__(self, foo): if foo != 1: raise Error("foo is not equal to 1!") and a unit test that is supposed to make sure the incorrect arg passed to the constructor properly raises an error: def testInsufficientArgs(self): foo = 0 self.assertRaises((Error), myClass = MyClass(Error, ...
In C++, I can have take input like this: cin >> a >> b >> c; And a can be int, b can be float, and c can be whatever... How do I do the same in python? input() and raw_input(), the way I'm using them, don't seem to be giving me the desired results. ...
Learning to program, trying to do this I have a string like this 2+24*48/32 and I want to split it into a list like this ['2', '+', '24', '*', '48', '/', '32'] I have messed around with .split() but that's messy as it returns a list, which means I would now have to iterate over two strings, etc ...
MIT abandoned its legendary 6.001 (Structure and Interpretation of Computer Programs) course and replaced it with 6.00, 6.01 and 6.02 in the new curriculum. They are AFAIK about Python and robots. What is your opinion about the loss of SICP and Scheme in computer science education? Is it a necessary step in the right direction or a bad m...
Why in this millenium should Python PEP-8 specify a maximum line length of 79 characters? Pretty much every code editor under the sun can handle longer lines. What to do with wrapping should be the choice of the content consumer, not the responsibility of the content creator. Are there any (legitimately) good reasons for adhering to 7...
For example: >>> x = [1, 1, 2, 'a', 'a', 3] >>> unique(x) [1, 2, 'a', 3] Assume list elements are hashable. Clarification: The result should keep the first duplicate in the list. For example, [1, 2, 3, 2, 3, 1] becomes [1, 2, 3]. ...