- Strength to Increase Rep
- +8
- Strength to Decrease Rep
- -2
- Upvotes Received
- 51
- Posts with Upvotes
- 45
- Upvoting Members
- 24
- Downvotes Received
- 12
- Posts with Downvotes
- 12
- Downvoting Members
- 7
118 Posted Topics
Re: "...head over to the sales websites..." Marketers. Their goal is to sell at any cost, and not to give you the best product for your needs. | |
Re: Don't separate the user id from the entry. [code]import csv, contextlib usernfo = {} with contextlib.closing(open()) as ifile: for entry in csv.DictReader(ifile): usernfo[entry['id']] = entry print(usernfo)[/code] | |
Re: One thing that I'm very glad I learned to do as a beginner and still use today - even though I'm probably still a beginner - is to have a basic file with code that is used more often than not in the script. I can copy this file each … | |
Re: Make an irc bot to connect to an irc server and channel and respond to users in various ways. Download irclib to get some code to start from. [url]http://irclib.bitlbee.org/[/url] If you can, get a copy of IRC Hacks published by O'Reilly. [url]http://www.jibble.org/irchacks/[/url] | |
Re: Dual boot with XP and whatever version of Unix/Linux has my fancy. | |
There is a security technique known as code signing. It basically generates a certificate for your code. This certificate first certifies the author of the code. Second, it has a value generated from the code. This value is unique to that code. If any changes are made to the code, … | |
Re: A picture or multiple pictures are just extremely small slices of a person's life. It doesn't represent the whole of person's life. There will be times when a manic person will be placid, or an agoraphobic person will go out in public. As long as someone is going to an … | |
Re: Task 1 is probably something that could be accomplished using system utilities if you were willing to research the options. I bet you could write a command line script or something to do it. Task 2 can have many approaches. If the program in question supports the right command line … | |
Re: Why do you need to check an object's mutability? Sounds like you need to solve a different problem or use a different solution. Technically you could try to make whatever changes you wanted to make and catch any AttributeError exceptions, but it still seems funny. So...? | |
Re: Builtins are the way to do it, but in your function you reset s to zero each loop because it is inside the loop. It needs to be set to zero before the loop. | |
Re: At present the survey requires only a username to participate. Aren't you concerned that someone might vote using other usernames? | |
Re: It depends on the structure of your file and what you are trying to do. To update (read and write) a file you usually open it with mode r+. From your other posts, I can see you are making a game. Are you trying to develop a save system or … | |
I had been wanting to write an IRC bot with asynchronous IO for a while. My bot responds to pings, but can be extended by defining functions and registering them to get called when the bot receives certain commands. My bot uses the RFC 1459 USER command and parameters, but … | |
Re: You can write a module that can also act as a script by using the idiom: if __name__ == '__main__': pass Importing a module and then executing the main body of that module is indicative of a design problem, but can be accomplished by wrapping the main body in a … | |
Re: The Python standard library features a csv module for CSV file reading and writing. Read the module documentation to learn how to use it. I'd use a dictionary or collections.OrderedDict to associate each unique key with a list of values. | |
Re: I think that if someone takes the time to get an abstract overview of programming languages, he or she finds that programming languages are relatively simple and those featuring the same [URL="http://en.wikipedia.org/wiki/Programming_paradigm"]programming paradigms[/URL] are quite similar. It's a fascinating subject. When a person studies a specific programming language, he or … | |
Re: [url]http://en.wikipedia.org/wiki/Pseudorandom_number_generator[/url] There is even a link to an algorithm with a psuedocode implementation. Personally, I think you should find something else to work on. I think reimplementing established algorithms will provide little educational value. | |
Re: [url]http://en.wikipedia.org/wiki/There's_more_than_one_way_to_do_it[/url] | |
I am doing some hobby coding regarding neural networks, and I was wondering if this is a correct and good use of abstract base classes or not. [code=PYTHON]import abc import collections import math import weakref class AbstractNeuron(metaclass=abc.ABCMeta): def __init__(self, weights, f=math.tanh, bias=1, biasWeight=0): self.weights = weights self.f = f self.bias … | |
Re: I've never used it, but the subprocess module may be what you need. It seems to feature a function that will start a subprocess and wait for the subprocess exit code. If the exit code is non-zero then the function will raise an exception. | |
Re: Sounds like an application for collections.Counter. First do the Python tutorial to learn the Python language. [url]http://docs.python.org/py3k/tutorial/index.html[/url] Then review the library reference to get an overview of Python's built in functionality. [url]http://docs.python.org/py3k/library/index.html[/url] Finally, read the documentation for collections and try to write your program. [url]http://docs.python.org/py3k/library/collections.html[/url] We can't help you if … | |
Hand evaluator for Texas Hold'em. If a "hand" has five or more cards, hand.rank will find the best five card hand the hand can form. Two hands can be compared using the comparison operators. The final hand can be gotten from the "hand" with hand.rank.hand. The value used for comparisons … | |
Re: Is this for production or is it just an exercise? If it is for production use bisect.insort to insert items into a list in sorted order. | |
Re: Seems like the big barrier here is that the poster's primary language must not be English. I tried searching for "moy", but I didn't get any promising results. Perhaps it is an abbreviation or truncation? | |
Re: As a designer and coder we should be as abstract as usefully possible. Abstract software is compact and reusable. You are treating classes as namespaces and making a specific class or function for every thing. You should treat classes as blueprints that abstractly specify the attributes and capabilities of a … | |
Re: Anyone with sufficient skills at Google could have found that information in the Python documentation. [url]http://www.lmgtfy.com/?q=python+dictionary[/url] [url]http://docs.python.org/tutorial/datastructures.html#dictionaries[/url] | |
Re: It's also possible to bin items to a collection like a set or list. This technique can bin items without key collisions. [code=PYTHON]import collections data = ((5.639792, 1.36), (4.844813, 1.89), (4.809105, 2.33), (3.954150, 2.69), (2.924234, 3.42), (1.532669, 4.50), (0.000000, 5.63)) bucket = collections.defaultdict(list) for each in data: bucket[int((each[1]))].append(each[0]) print(bucket) [/code] | |
Re: It's not unusual for early implementations of code to be excessive or unrefined. The important thing is to refactor as necessary. [url]http://en.wikipedia.org/wiki/Code_refactoring[/url] Your early implementations and final versions will improve over time if you learn more about Python, plan what you want your code to do, decompose data and functions, … | |
I'm working on a project where I would like to compare collections of words, but I have additional constraints I need to account for. The collections are like a set in that order doesn't matter for the comparison. However, in my problem equal elements are significant. E.g. the collection of … | |
I'm interested in a generic event system for Python. I've searched the forum for similar topics, and I've searched the web for existing implementations. I haven't found exactly what I'm looking for. I'm familiar with the Observer pattern. However, my implementation and other implementations lack strong support for concurrency and … | |
Re: [COLOR="Green"]creature.metabolism[/COLOR] [COLOR="Red"]creature.metabolsim[/COLOR] | |
Re: Smart thinking. I might drop back by and add some stuff. I would make a minor gripe. Attributes and methods with two leading underscores and no trailing underscores are mangled by Python. I know your intention is to indicate that these attributes and methods should not be accessed externally, but … | |
Re: I like using dictionaries for my multidimensional containers using coordinate tuples as keys. It's not a conventional approach, but despite any disadvantages it has some advantages. For very small or very large coordinates, it has a memory advantage because "coordinates" don't need to exist until they are assigned to. The … | |
Re: If you can, check out the fractions module. [url]http://docs.python.org/library/fractions.html#module-fractions[/url] The source is included with Python. If you can locate it, you can see how the author(s) did it. | |
Re: Isn't this what the bisect module is for? | |
Re: Use an online resource that makes it easy to retrieve data. Many sites have an API (Application Programming Interface) that allow programs to retrieve data with a few function calls. For instance, Yahoo lets you retrieve a csv file of stock quotes with a url. You can use the urllib.retrieve … | |
Re: Implement a custom importer in conformance with PEP 302 utilizing code from the "importlib" and "imp" modules. This importer can emulate Python import functionality, or you can alter it to suit your desired behavior. For instance, implement an importer that returns a copy of a module instead of modules stored … | |
Re: Have you tried making a client locally and getting it to connect? Maybe the reason select fails to return any sockets is because no one is trying to connect. (Therefore there are no sockets to call accept on.) Maybe you should try making a client instead of a server. You … | |
Re: I like to code a simple switch using True or False. When you need to flip the switch then changing state is as easy as: [code=PYTHON]#Switch in the 'off' state state = False #Flip the switch state = not state #Switch is now in the 'on' state #Flip again state … | |
Re: Python comes with a csv module you should use to extract the data. Search your documentation for how to write to files. The way you are doing it is totally wrong. | |
Re: An object is just an abstraction of data and functions. An object has attributes (data) and methods (functions that interact with its attributes). A class is a blueprint describing the objects created from it. When you write a class you are 'declaring' a class. An object created from a class … | |
Re: Do you want to do a graphical application or a console application? | |
Re: I make my user input loops follow this pattern: [code=PYTHON] #Start a loop that will run indefinitely. while True: i = input("Prompt: ") #Here I do my input checking. In this example it checks that i isn't an empty string. if i: #Break out of the indefinite loop. break[/code] | |
Re: I was looking for a high level language to program a.i. in and after trying AutoHotkey I decided to try Python since it provides standard library support for more processing primitives. (Threading and multiprocessing.) | |
Re: redyugi showed you. Phill should be an instance of a Hero class. | |
Re: Here's Python 3.x code I wrote for cards and decks. Maybe it will give you some inspiration. [url]http://pastebin.com/wujeXQjV[/url] In most implementations, suits and ranks are simply represented by numbers. I make my implementation only slightly more complex for extra expressiveness. (My suits have symbols and words, and my ranks have … | |
Re: You are right that checking is terribly inefficient. Use messaging instead of checking. (When an event happens, make that system send a notification to the systems waiting on it.) There are packages for event systems out there. I can't recommend one, but search and check out the source. You might … | |
Re: The @ symbol is syntax indicating a decorator. In this instance, the decorator takes the function it decorates (a.k.a. wraps) and makes a new function that starts the old function in a new thread. A normal decorator will not preserve the name and docstring of the old function, but @wraps … | |
Re: Seems to me like it would be good to use both concurrently. I've all ready written a few scripts that can run with both 2.x and 3.x. Python packages and modules are open source. If you ever want them for a new version you can always refactor the old version. … | |
Re: God I want to smack the creators of some of those courses upside the head with a thick book. |
The End.