118 Posted Topics

Member Avatar for Ghostenshell

Couple of problems. The first is poor class implementation. It's OK to make your class without attribute getters and setters. You can access instance attributes by referring to the attributes themselves. [code]class Car: def __init__(self, year): self.year = year mycar = Car(1999) mycar.year[/code] The second problem with implementation is that …

Member Avatar for Ghostenshell
0
105
Member Avatar for rexona

Typecasting the numbers to a string doesn't make much sense to me, but whatever. You are mistakenly using the sample function. Here's what you want to do. [code]import random def make_secret(numdigits): a = [] for i in range(numdigits): a.append(str(random.randrange(0, 10))) return a[/code]

Member Avatar for snippsat
0
186
Member Avatar for ultimatebuster

It's bad because it isn't friendly to other objects that act like your class. You should use hasattr instead to check that the object you are working with is appropriate. That way as long as the object has the required attribute or method it will work with your code as …

Member Avatar for TrustyTony
0
188
Member Avatar for frankinaround

[url]http://github.com/pepijndevos/PyMouse[/url] Automated mouse control is a somewhat esoteric programming feature. You may have to experiment, research, and refactor other code to get a solution.

Member Avatar for vegaseat
0
100
Member Avatar for Tarkenfire

If you don't mind me asking, what are the "ircbot" and "irclib" modules or packages you imported, and where could we acquire them or view the source?

Member Avatar for Tarkenfire
0
229
Member Avatar for john125

A technical term for creating a class is 'declare'. When you create a class you are declaring a class, and when you see a class in code it is a class declaration. Just thought you might want to know the lingo. b

Member Avatar for Beat_Slayer
0
2K
Member Avatar for ke24126

Seems to me like this would be a great opportunity to apply and use object oriented programming. A card is a type of object. What I would try is to make a card class with rank and suit attributes. Then I'd add comparison methods to compare card rank. (I'm assuming …

Member Avatar for bpatt22
0
4K
Member Avatar for akls578

Are you sure you want to use bubble sort? [url]http://en.wikipedia.org/wiki/Bubble_sort#Performance[/url] According to the Wikipedia article it is one of the worst sorting algorithms.

Member Avatar for TrustyTony
0
409
Member Avatar for jtaylor-bye

[url]http://www.devshed.com/c/a/Python/Object-Oriented-Programming-With-Python-part-1/[/url]

Member Avatar for lrh9
0
138
Member Avatar for ultimatebuster

Try relative imports. [url]http://www.python.org/dev/peps/pep-0328/#guido-s-decision[/url] Seem like just the thing. I've used them. They permit you to import modules from a relative parent package. They're hard to figure out though. The documentation is somewhat lacking so you might have to tinker until you get it right.

Member Avatar for lrh9
0
159
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
453
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
264
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
167
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
120
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
768
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
107
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
460
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
149
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
174
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
196
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
117
Member Avatar for hondros
Member Avatar for lrh9
0
144
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
338
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
837
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
349
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
162
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
318
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
95
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
129
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
65
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
190
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
263
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
144
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
Member Avatar for lrh9

I'm wondering if it's possible to change the border color of a tkinter entry widget border. I don't think it is, because no such option exists in relevant documentation. You can change the width, but that just results in the whitespace being recessed - creating a raised 3d border. If …

Member Avatar for Ene Uran
0
12K
Member Avatar for AutoPython

If it interests you, I think that the code for Python's IDLE is available in the Python library. If it is, you can edit it to your liking.

Member Avatar for Gribouillis
0
174
Member Avatar for ffs82defxp

There are other options as well. Make both functions methods of a class, and use class attributes to store relevant data. Combine both functions into one.

Member Avatar for vegaseat
0
381
Member Avatar for vegaseat

I remember watching a Stargate SG-1 episode called "Torment of Tantalus", and SG-1 find an ancient repository of information created by a council of allied alien races. The first page was a glossary containing basic definitions for the language in the repository, and it was a 3d hologram of the …

Member Avatar for Brian Barker
0
239
Member Avatar for ShadyTyrant

I'm just wondering why the Library class has a container for book information. Is the book information a temporary container?

Member Avatar for ShadyTyrant
2
262
Member Avatar for Ene Uran

For Christmas? The meal usually. Next year I'm thinking about celebrating Hanukkah, but I'll have to learn about it first.

Member Avatar for roshini.johri
1
117
Member Avatar for lrh9

Hello. I'm lrh9, a new user. This is my first time visiting these forums. I've posted on [url]www.programmingforums.org[/url] under the same user name. I'm a hobbyist and amateur computer programmer. My primary languages are C++, a custom scripting language for Windows named AutoHotkey, and Python which I've just started out …

Member Avatar for lrh9
1
230
Member Avatar for kapcom01
Member Avatar for Yeen

According to your code, you are replacing all periods with spaces. If you want to replace the dots with absolutely nothing, then use two quotes side by side. "" However, as for the script itself. Seems to me if you moved the outfile.write() outside of the loop, and changed it …

Member Avatar for Stefano Mtangoo
0
3K
Member Avatar for gunbuster363

[QUOTE=gunbuster363;1046880]I do this: link = soup.find(attrs={'class' : re.compile("util2$")}) print dir(link) what appear is: OMG[/QUOTE] You can import the module pprint, and using the function pprint, you can display each function and variable on its own line. [CODE]from pprint import pprint link = soup.find(attrs={'class':re.compile("util2$")}) pprint(dir(link))[/CODE]

Member Avatar for gunbuster363
0
2K

The End.