User Profile

Collapse

Profile Sidebar

Collapse
elcron
elcron
Joined: Sep 13 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • elcron
    replied to Web Apps in Python... Where Do I Start?
    I'd recommend Django . It has a nice tutorial on how to write a poll app and is very pythonic :)
    See more | Go to post

    Leave a comment:


  • elcron
    replied to Does None reserve any space in memory?
    Try using a set, they're unordered an I believe faster than a list it also supports unions, intersections and differences which may or may not help

    Code:
    >>> s = set(i for i in xrange(101))
    >>> s
    set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
    ...
    See more | Go to post

    Leave a comment:


  • elcron
    replied to User input and classes
    You could overload the __repr__ function to fix that.

    Code:
    >>> class C:
    	def __repr__(self):
    		return "Test"
    
    >>> C
    <class __main__.C at 0x860e68c>
    >>> C()
    Test
    >>> [C(), C(), C()]
    [Test, Test, Test]
    See more | Go to post

    Leave a comment:


  • elcron
    replied to User input and classes
    You're only storing the last created person. You could use a list to store all of the people created.

    [code=Python]run = 1
    class Person:
    people = []
    def __init__(self, name):
    self.name = name
    Person.people.a ppend(self)
    def sayHi(self):
    print 'Hello, my name is', self.name
    def countPeople(sel f):
    print 'There are %d people...
    See more | Go to post

    Leave a comment:


  • elcron
    replied to Django
    Try here for a video tutorial or here....
    See more | Go to post

    Leave a comment:


  • elcron
    replied to Python Weblog
    You can use django, http://www.djangoproje ct.com/, as the framework. Here's a tutorial on howto create a wiki with it,http://showmedo.com/videos/series?name=v7k ABKL6R....
    See more | Go to post

    Leave a comment:


  • elcron
    replied to Getting out of a recursive function...
    Try replacing it with a while loop. A while loop will continuously execute all the code inside while the condition is true. Also the keyword break will exit the loop.
    [CODE=python]
    while someCondition:
    # execute some code
    [/CODE]...
    See more | Go to post

    Leave a comment:


  • elcron
    replied to Python circular class inclusion
    Just start the block with [code=python][code=python][/code]

    But I think he means something like
    [CODE=python]
    class Foo():
    def __init__(self):
    self.b = Bar()

    class Bar():
    def __init__(self):
    self.f = Foo()

    f = Foo()
    [/CODE]
    A fix would be something like
    [CODE=python]
    class Foo():
    def __init__(self, bar=None):
    self.b...
    See more | Go to post

    Leave a comment:


  • elcron
    replied to Set Excel cell to a value using Python
    I believe their is a module to read and write excel files but you could always just save it as a CSV file (comma separated values) and write a quick reader for it.
    See more | Go to post

    Leave a comment:


  • I believe saving it with the .pyw extension should fix that....
    See more | Go to post

    Leave a comment:


  • elcron
    replied to Help with Printing Matrix Grid
    You can access nested lists the same you could try something like li[i][j] but the following is more scalable
    [code=python]
    if True:
    lol = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

    print "Columns %s"%( " ".join([str(j) for j in range(len(lol[0])]) )
    for i in range(0,len(lol )):
    print " Row %s: %s"%(i, " ".join( [str(j) for j in lol[i]]))
    [/code]...
    See more | Go to post

    Leave a comment:


  • elcron
    replied to Basic Python Validation
    Use try except to handle errors.

    [code=python]
    try:
    n = int( raw_input("Ente r a number: ") )
    print "n=%s, n squared=%s"%(n, n*n)
    except ValueError:
    print "Invalid input."
    [/code]
    See more | Go to post

    Leave a comment:


  • elcron
    replied to another beginner game question
    Can you post some code. Use a for loop for the loop.
    [code=python]
    def flipCoin():
    #...

    for i in xrange(100):
    print flipCoin()
    [/code]...
    See more | Go to post

    Leave a comment:


  • elcron
    replied to passing argument to python exexutable
    np always glad to help :)...
    See more | Go to post

    Leave a comment:


  • elcron
    replied to Noob needs help on very simple question
    Django seems to accomplish this although it may do it this way.

    [code=python]
    import sys

    def sayHello(name):
    print "Hello, %s!"%name

    def main():
    if len(sys.argv) >= 2:
    if sys.argv[1] == "sayHello" and len(sys.argv) == 3:
    sayHello(sys.ar gv[2])

    main()

    # output in command prompt
    python...
    See more | Go to post

    Leave a comment:


  • elcron
    replied to passing argument to python exexutable
    Django seems to accomplish this although it may do it this way.

    [code=python]
    import sys

    def sayHello(name):
    print "Hello, %s!"%name

    def main():
    if len(sys.argv) >= 2:
    if sys.argv[1] == "sayHello" and len(sys.argv) == 3:
    sayHello(sys.ar gv[2])

    main()

    # output in command prompt
    python...
    See more | Go to post

    Leave a comment:


  • elcron
    replied to passing argument to python exexutable
    Since the format for a script is "python test.py function arg1 arg2 .. .argx"(without quotes) an exe would probably be somthing like "test[.exe] function arg1 arg2 .. .argx"(also without quotes)...
    See more | Go to post

    Leave a comment:


  • elcron
    replied to Noob needs help on very simple question
    Functions need to be called on to run. also no code can go after the return statement.

    [code=python]
    def square(x):
    n = x*x
    print "hello world"
    return n

    square(2)
    [/code]
    Or try removing the quotes and something like this, python test.py square(2), should work...
    See more | Go to post

    Leave a comment:


  • elcron
    replied to [ask]could not open pic in pygame
    It looks like your missing the extension.
    ie. *.jpg *.gif *.png etc.
    See more | Go to post

    Leave a comment:


  • elcron
    replied to Printing out an answer in quotes
    You can escape quotes with "\" but it usually better to avoid it unless you're nesting multiple layers of quotes.
    [code=python]
    >>> print "\""
    "
    >>> answer = 15
    >>> print "\"%s\""%(answe r)
    "15"
    [/code]
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...