118 Posted Topics
Re: 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 … | |
Re: [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 … | |
Re: 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 … | |
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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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. … | |
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. | |
Re: 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 … | |
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, … | |
![]() | Re: 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 … |
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? | |
Re: 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 … | |
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 … | |
Re: 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 … | |
Re: 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 … | |
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 … | |
Re: Check out the "code" module. It has functions to emulate a Python interpreter. | |
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 … | |
Re: 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 … | |
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. … | |
(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, … | |
Re: 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. | |
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 … | |
Re: 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? | |
Re: 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 … | |
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 … | |
Re: 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) … | |
Re: 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 … | |
Re: [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 … |
The End.