- Strength to Increase Rep
- +6
- Strength to Decrease Rep
- -1
- Upvotes Received
- 35
- Posts with Upvotes
- 32
- Upvoting Members
- 21
- Downvotes Received
- 3
- Posts with Downvotes
- 3
- Downvoting Members
- 2
I love Python!
I often play with D and C#.
- Interests
- School Biology Chemistry
- PC Specs
- Windows 7 OpenSUSE Ubuntu Netbook Edition
Re: Here's a really evil Hello World program. You see, in Python, type(type)==type, so with that in mind, Classes are a type of type, which means that they inherit from type. So really, you can actually define a class by initiating a type of it, and then defining a classDict for … | |
Re: Here is [B]code[/B] for a [B]GUI[/B] program in [B]IronPython[/B], which is a [B]cross-platform[/B] (and of course cross-browser) implementation of CPython that has the exact same syntax. With IronPython you can use .NET with Python. This is [B]not[/B] a question. It's a code snippet for a GUI program. Pretty neat alternative … | |
Re: Wouldn't be something like this? : [CODE] def main(): fname = raw_input ("Enter filename:") infile = open(fname,"r") data = infile.readlines() infile.close() items = len(data) print items, "number of items." main() [/CODE] You should add a try:/except: because the filename the user might be trying might not exist. | |
Re: C++ is a big thing to learn. It's really big. If you like Python (I'm a huge fan), you can use panda3d, which in my opinion is the simplest option, especially if you have a background in Python. | |
Re: Javascript isn't too hard to understand. Perhaps you can give us the javascript code. | |
Re: [QUOTE=tonyjv;1252311]In math.sqrt the math is module and sqrt is function. Nothing to do with objects.[/QUOTE] Well, not exactly [I]nothing[/I] to do with objects, if you realize that functions are in fact objects. But you are right, math is the module. Overall, very good tutorial on the basics of classes and … | |
Re: This is not a good implementation of the sieve algorithm. | |
Re: I have some comments on your code. [CODE]import struct as S import Blender def HexToDec(n): #return float(S.unpack("<h", S.pack("<H", int((n.encode('hex')), 16)))[0]) #jcao219: please keep lines short, so it is readable nhex = int(n.encode('hex'), 16) packed = S.pack("<H", nhex) unpacked = S.unpack("<h", packed)[0] return float(unpacked) def readvert(v): #jcao219:where do you use this … | |
Re: I was able to compile it with IronPython's compiler, so I can give you that, if you don't mind it running on .NET of course. | |
Re: [QUOTE=tonyjv;1296859]Could be that that module you want would work with IronPython or what you say IronPython gurus? Or the program could be complied to library (dll in Windows) and used as Python library with [URL="http://docs.python.org/library/ctypes.html"]ctypes[/URL]. Or you could see if [URL="http://code.google.com/p/shedskin/"]shedskin[/URL] could manage to turn all your code to C++ … | |
Re: You can use WolframAlpha for graphing. I'm not sure what you want your program to do. | |
Re: This method is great for basic cryptography in Python, however advanced and secure encryptions such as AES offer the best degree of security. For those of you interested in that, PyCrypto is for you. | |
Re: Well, if you want to be able to do this: [icode]for i in numberstack[/icode], you have to write the stack like this: [code] class Stack: """doc omitted""" def __init__(self,size): self.data = [None]*size self.size = 0 def push(self,item): self.data[self.size] = item self.size = self.size + 1 def pop(self): self.size = self.size … | |
Re: There really is no fool-proof way, for any application written in any language. For C#, someone could maybe use Reflector and then see what creative registration processes you have written, unless if you obfuscate the code, which only makes it harder, never fool-proof. Good luck. | |
Re: First of all don't use "globals" or "locals" as your identifiers, they are built-in functions. One possibility to fix this is to do this: [CODE]#execfile('comp1.py') def exefi(name, globalsmap=None, localsmap=None): if localsmap or globalsmap: exec compile(open(name).read(), name, 'exec') in globalsmap, localsmap else: exec compile(open(name).read(), name, 'exec') in globals() exefi('comp1.py')[/CODE] Another is … | |
Re: You could do that in Python, but since you are beginning Python, why not just use a service such as OpenDNS (which would be much easier to set up), instead of trying to deal with sockets, etc? | |
Re: What are you using, BaseHTTPServer? | |
Re: [code]for file in [f for f in files if f.endswith(".html" or ".htm" or ".txt")]:[/code] is equal to [code]for file in [f for f in files if f.endswith(False)]:[/code] Don't use "file" as a variable name (identifier) since it's builtin. Escape [icode]"C:\New Folder"[/icode] as [icode]"C:\\New Folder"[/icode] or add an "r" before the … | |
Re: Lua has a really small standard library. Also, I think it's used a lot as a game scripting language. | |
Re: [CODE]with open("scores.dat") as fileIn: for line in fileIn: if line: parse(line)[/CODE] (Something like that, I'm not sure if I wrote that correctly. I haven't been doing much Python lately.) | |
Re: For windows you can use the msvcrt module: [CODE]import msvcrt import sys time_is_up = False #use threads to modify this userinput = "" while True: if msvcrt.kbhit(): ch = msvcrt.getch() if ch != "\r" and not time_is_up: userinput += ch sys.stdout.write(ch) else: break[/CODE] | |
Re: One thing you have to be careful of is this tricky stumbling point (which arises because Python's lists are mutable): [CODE]>>> a = [[None]*3]*3 >>> a [[None, None, None], [None, None, None], [None, None, None]] >>> a[0].append("Hello") >>> a [[None, None, None, 'Hello'], [None, None, None, 'Hello'], [None, None, None, … | |
| Re: It may be easier to understand when you take comprehensions out. [CODE]def myfunc(x): ret = [] for i in range(2**len(x)): res = [] for j, y in enumerate(x): if (i >> j) & 1: res.append(y) ret.append(res) return ret[/CODE] |
Re: I thought os.kill didn't work on Windows... [URL="http://docs.python.org/faq/windows.html#how-do-i-emulate-os-kill-in-windows"]http://docs.python.org/faq/windows.html#how-do-i-emulate-os-kill-in-windows[/URL] I see it now works on 2.7 and 3.2. I guess you are on linux. | |
Re: [QUOTE=Gribouillis;1296241]0xfe is not the hex of -2, it is the hex of 256 - 2. You can use [code=python] >>> hex(-2 % 256) '0xfe' >>> hex(256 - 2) '0xfe' [/code][/QUOTE] Actually, it is for byte. If I can remember correctly, Windows, -2 is: [INDENT]Qword (long) = 0xFFFFFFFFFFFFFFFE Dword (int) = … | |
Re: [QUOTE=tonyjv;1291565]Maybe the poster liked to have list containing integer length instead of the element for every element of the list. Then for line 5 use statement to return list of counts. What happens or is supposed to happen if the elements are numbers? Maybe len(str(element)) is better to add to … | |
Re: No, you have to save it to a temp file. You can't expect software to be able to read your program's memory. | |
Re: Well, at first I thought what you want to do would require the traceback module. Now that I think about it, I think you use id. [CODE]def get_var_name(arg): for x in globals(): if id(globals()[x]) == id(arg): return x return[/CODE] |