118 Posted Topics

Member Avatar for cwarn23

I think the humane treatment of animals - insofar as we should not cause unnecessary distress or pain - is a reasonable standard for law, but otherwise I'm a proponent for the use of animal resources to support and advance human lives. But no to human rights for animals. Basically …

Member Avatar for GrimJack
1
451
Member Avatar for aframe

[code]import configparser import os import sys config = configparser.ConfigParser() #If the script is executed __name__ will be '__main__' and sys.argv[0] will be the full path of the script. if __name__ == '__main__': path = os.path.dirname(sys.argv[0]) #Else the script was imported as a module and it has a __file__ attribute that …

Member Avatar for griswolf
0
2K
Member Avatar for frankinaround

To express my opinion frankly, the instructions are stupid. I'll explain why later. However, let me see if I can help. We're looking at Problem 2? In this problem you are implementing a custom container class to hold shape objects. The main purposes of this container are to ensure that …

Member Avatar for TrustyTony
0
261
Member Avatar for lrh9

I know that certain functions will check the script's or module's current directory for the file if no path is specified. [code=PYTHON]open('test.txt')[/code] If that script is run and test.txt is in the same directory that will open the correct file. However, if I try to import that module it doesn't …

Member Avatar for lrh9
0
2K
Member Avatar for Mathhax0r

Try using decorators. They are a language feature in at least Python 3.0 that perform code on a function or method defined after them. Optionally, they can return a new function that will be assigned to the newly defined function. There are function decorators and class decorators. I haven't studied …

Member Avatar for jcao219
0
11K
Member Avatar for DifficultUsrnme

I'd answer number 1 a little differently than Gribouillis. Technically everything under the hood is entirely object oriented and you can certainly write pure object oriented programs in Python, but it is also possible to write programs in a purely functional style as well. As for number 5? [quote]You can …

Member Avatar for DifficultUsrnme
0
165
Member Avatar for letlet_pogs

First, Python doesn't use semicolons to terminate lines of code. P.S. Someone beat me to it, but maybe I can help a little more. A fairly quick way to accomplish what you wish to accomplish is to create a set of the string and then check the length of that. …

Member Avatar for lrh9
0
117
Member Avatar for lrh9

U.S. Military Weapons Inscribed With Secret 'Jesus' Bible Codes Pentagon Supplier for Rifle Sights Says It Has 'Always' Added New Testament References [URL="http://abcnews.go.com/Blotter/us-military-weapons-inscribed-secret-jesus-bible-codes/story?id=9575794"]http://abcnews.go.com/Blotter/us-military-weapons-inscribed-secret-jesus-bible-codes/story?id=9575794[/URL] I saw this. I think this is wrong.

Member Avatar for jwenting
1
766
Member Avatar for gunbuster363

Gribouillis makes some good suggestions. As for storing the data to a file there are really two standard, commonplace options that I think are suited to this. I'd either pickle or marshal the object. pickle and marshal can store and retrieve a Python object on file. Both are similar, but …

Member Avatar for lrh9
0
105
Member Avatar for lrh9

I'm having a problem with 'os.path.getmtime'. I've been doing some research into generating '.pyc' files and I am able to retrieve the source modification time (in seconds) as recorded in the '.pyc' file. It is merely the second set of four bytes unpacked as a long integer. [code=Python] import random, …

Member Avatar for lrh9
0
2K
Member Avatar for polygon

That's going to be a tougher one if I think you are asking for a procedure that can work on lists with mixed items in them down to an arbitrary number of levels. In a real application you could probably find a better way of representing the data and use …

Member Avatar for Gribouillis
0
2K
Member Avatar for lrh9

I was wondering if anyone knows of any resources about building a custom importer. I've found this: [url]http://www.doughellmann.com/PyMOTW/sys/imports.html[/url]. I am also aware of PEP 302 and PEP 369 and imp and importlib. Are there any other resources I might need?

Member Avatar for lrh9
1
457
Member Avatar for cnuzzo

Object oriented programming has some advantages in virtually all situations, even if functional programming is sometimes easier to write. That's why I generally tend to encourage its use over functional programming, but make no mistake that a poorly conceptually designed program will be harder to write using object oriented programming …

Member Avatar for Gribouillis
0
146
Member Avatar for lrh9

I've seen these in documentation, namely in the "importlib" documentation for Python 3.1, and I'm wondering what the difference is between a "universal newline" and a "standard newline", if any. I know it has to do with the byte sequence that is used to represent newlines, and I think universal …

Member Avatar for HiHe
0
172
Member Avatar for axa121

If you find a solution to one of your own problems, it is considered polite to post the solution regardless because other people might also have the same problem. As for my solution to the problem statement? I'd probably just strip the string of any non-alphabetic characters excepting spaces and …

Member Avatar for woooee
0
3K
Member Avatar for jmoran19

The Timer executes the code in a new namespace. This namespace doesn't know lista and listb because they are not in the name space. If you create a module that declares and sets these variables, you could then import it using the Timer's setup statement. (If you need the cell …

Member Avatar for lrh9
0
194
Member Avatar for lrh9

I'm using the code module to add an interactive interpreter to an object. This object has an interact method that when called creates an interactive interpreter with the object's dictionary as the namespace for the interpreter. When done interacting with the object, I want the "exit" function to return execution …

Member Avatar for lrh9
0
115
Member Avatar for hondros
Member Avatar for lrh9
0
143
Member Avatar for lrh9

I'm just wondering if it is possible to import a module as an object attribute. The basic description of what I want to accomplish is that I'm creating a software agent object. This agent will have a set of abilities (functions), but I don't know what these are ahead of …

Member Avatar for lrh9
1
336
Member Avatar for khess

Without supporting or opposing cloud computing and cloud operating and software services, the statement that desktop computers will always exist for resource intensive applications may not be true. The primary factor preventing centralized, networked systems from providing resource intensive services is data transfer width and rate. With modern operating systems …

Member Avatar for lrh9
-3
831
Member Avatar for lrh9

And I can't get anything I write to work. I'm so far off course I think I just need a working example of import hooks in action. I've looked for examples on the Internet, but they only show what looks like correct code. They never show that code in action. …

Member Avatar for lrh9
0
347
Member Avatar for lrh9

(A quine is a program that produces its own source as its output, typically to a file.) [CODE=Python]import sys ifile = sys.argv[0] counter = 0 istream = open(ifile) source = istream.readlines() source[2] = 'counter = ' + str(counter + 1) + '\n' if counter == 0: original = str(ifile) source.insert(5, …

Member Avatar for dwks
0
160
Member Avatar for cwarn23

Well. According to the inductive reasoning involving the first law of thermodynamics, we can be fairly confident that the universe has existed in some form or another for eternity. It just may have been in a form we cannot currently learn about or understand.

Member Avatar for Dope 7560
0
317
Member Avatar for lrh9

I'm thinking about writing a small command line directory management program in Python. The most basic functionality I want is to be able to compare the the files in a directory and sub-directory, and if there are any duplicates then delete the lower most duplicate. I all ready have a …

Member Avatar for Gribouillis
0
93
Member Avatar for wildplace

Edit: I'm sorry. I didn't realize that you wanted the button to set up a condition so that if another button is pressed something would be executed, or do you just want to check which button called the function?

Member Avatar for lrh9
0
128
Member Avatar for faded jeans

1) Thread titles should be descriptive. A generic request for help is not descriptive. 2) This appears to be homework. Part of homework is to take the initiative to learn for yourself. That means you must complete the essential portions of the assignment for yourself. No one will do it …

Member Avatar for lrh9
-2
63
Member Avatar for lrh9

Lately I've been writing a lot of code involving the creation of new objects, and I quickly come to find that Python almost always creates a reference to an object instead of a new object. I understand the importance of conserving memory usage, but in this instance I actually need …

Member Avatar for lrh9
0
187
Member Avatar for lewashby

The class if functionally correct. A few things I'd like to suggest. 1) As far as I'm aware, protected names usually begin with one underscore. [CODE]self._name #"Correct" self.__name #"Incorrect"[/CODE] 2) I'd probably put an underscore in front of "get_name" and "set_name" and use the property to handle attribute access. 3) …

Member Avatar for lrh9
0
262
Member Avatar for need help!

Whitespace is recommended to make Python code clearer. Traditionally there is no space between related lines of code. A single line is recommended between different code sections and function definitions. Two lines are recommended between class definitions and I use two lines in method declarations if the methods are different …

Member Avatar for need help!
0
142
Member Avatar for mahela007

[QUOTE=mahela007;1062614] So how, then, does Tk manage to provide windows which look 'native' for the different operating systems? [/QUOTE] I don't know the way it technically does it, but my best guess is that it uses an API - application programming interface - to standardize how it draws widgets without …

Member Avatar for vegaseat
0
1K

The End.