Two Plus Two Publishing LLC Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > Other Topics > Programming

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 05-03-2011, 08:12 AM   #46
Carpal \'Tunnel
 
jjshabado's Avatar
 
Join Date: Jul 2006
Posts: 13,842
Re: ** Python Support Thread **

Like RoundTower mentioned, in that specific case you should probably just do:

Quote:
v = dic.get(keyVal, -1)
In the more general case, I kind of agree that I've never felt that easy with the really common use of exceptions. On one hand I've had the "only use exceptions for truly exceptional situations" mantra drilled into my head for awhile - and generally agree with it. On the other hand, its handy to not have a lot of special in-band return values that need to be checked for/handled.
jjshabado is offline   Reply With Quote
Old 06-01-2011, 06:32 PM   #47
Pooh-Bah
 
Aceium's Avatar
 
Join Date: Jan 2007
Location: Kansas
Posts: 5,172
Re: ** Python Support Thread **

I'm coming from using C++. The last formal instruction I had was in college. I was using Dev-C++ as my programming kit/compiler. So I'm a little lost as to how exactly Python works as a scripting language. Is there a front-end that I'll be working with?
Aceium is offline   Reply With Quote
Old 06-01-2011, 06:47 PM   #48
Pooh-Bah
 
TheIrishThug's Avatar
 
Join Date: Jan 2005
Location: Belligerent and numerous
Posts: 5,217
Re: ** Python Support Thread **

Since Python is not statically compiled, you don't really need an IDE. Typing
Code:
python myScript.py
on the command line is enough to run your program.

That being said, there are Python IDEs available.
TheIrishThug is offline   Reply With Quote
Old 06-02-2011, 02:16 AM   #49
stranger
 
Join Date: May 2011
Posts: 11
Re: ** Python Support Thread **

You do not need IDE. In case you need to debug you can use print function. This by far best and superior way for writing programs.

For simple editor you can use IDLE (it comes whit python distribution), but if you really think that you can not live without VisualStudio look like software, debugger and code completion try using Eclipse whit Pydev plugin.
ralu is offline   Reply With Quote
Old 06-02-2011, 03:15 AM   #50
King of the sidebar
 
Neil S's Avatar
 
Join Date: Sep 2004
Location: Northern Virginia
Posts: 16,431
Re: ** Python Support Thread **

Quote:
Originally Posted by ralu View Post
You do not need IDE. In case you need to debug you can use print function. This by far best and superior way for writing programs.


Bash IDEs all you want but please, please learn there's more to debugging than print statements. Sometimes a full debugger is overkill... but sometimes a debugger is the only way.
Neil S is offline   Reply With Quote
Old 06-02-2011, 09:16 AM   #51
Carpal \'Tunnel
 
jjshabado's Avatar
 
Join Date: Jul 2006
Posts: 13,842
Re: ** Python Support Thread **

Quote:
Originally Posted by Neil S View Post
Bash IDEs all you want but please, please learn there's more to debugging than print statements. Sometimes a full debugger is overkill... but sometimes a debugger is the only way.
Indeed. If someone told me that they never used a debugger... I wouldn't work with that person.

And this is coming from someone that uses Print statements way too often.
jjshabado is offline   Reply With Quote
Old 06-02-2011, 10:57 AM   #52
Carpal \'Tunnel
 
ArturiusX's Avatar
 
Join Date: Sep 2004
Posts: 19,114
Re: ** Python Support Thread **

Quote:
Originally Posted by ralu View Post
You do not need IDE. In case you need to debug you can use print function. This by far best and superior way for writing programs.

For simple editor you can use IDLE (it comes whit python distribution), but if you really think that you can not live without VisualStudio look like software, debugger and code completion try using Eclipse whit Pydev plugin.
What the hell? Isn't half the reason why python is awesome is the PDB module and the add-ons you can use with it? Do you really just use print statements over PDB? Really?
ArturiusX is offline   Reply With Quote
Old 06-02-2011, 02:57 PM   #53
Pooh-Bah
 
Aceium's Avatar
 
Join Date: Jan 2007
Location: Kansas
Posts: 5,172
Re: ** Python Support Thread **

After messing with it a bit, I figured out that I can develop .py files and then execute them directly from the cmd line. Simple!
Aceium is offline   Reply With Quote
Old 06-02-2011, 06:13 PM   #54
King of the sidebar
 
Neil S's Avatar
 
Join Date: Sep 2004
Location: Northern Virginia
Posts: 16,431
Re: ** Python Support Thread **

Quote:
Originally Posted by jjshabado View Post
Indeed. If someone told me that they never used a debugger... I wouldn't work with that person.

And this is coming from someone that uses Print statements way too often.
Ditto. I'll print/NSLog/whatever all day long. But when you need the debugger.. well, just use it. It's not hard.
Neil S is offline   Reply With Quote
Old 06-08-2011, 10:19 PM   #55
veteran
 
Slap My Jack's Avatar
 
Join Date: Jan 2006
Location: Pimpville
Posts: 2,986
Re: ** Python Support Thread **

Quote:
Originally Posted by ralu View Post
You do not need IDE. In case you need to debug you can use print function. This by far best and superior way for writing programs.
Relying on print statements for debugging anything of increasing complexity can become a bad habit, according to what I've learned.

I do agree that an IDE is not critical though, but it can be convenient. I prefer Emacs, but I also use an IDE too.

Wing IDE is a Python specific IDE that's free for non-commercial purposes. It doesn't have any overhead to setting it up (unlike Eclipse), so it can be good for beginners. And Eclipse has already been mentioned.
Slap My Jack is offline   Reply With Quote
Old 06-09-2011, 12:07 PM   #56
Pooh-Bah
 
Aceium's Avatar
 
Join Date: Jan 2007
Location: Kansas
Posts: 5,172
Re: ** Python Support Thread **

What type of debugger do you use with Python? Is there a program that will allow you to step through instructions and inspect values along the way?
Aceium is offline   Reply With Quote
Old 06-09-2011, 12:08 PM   #57
Carpal \'Tunnel
 
jjshabado's Avatar
 
Join Date: Jul 2006
Posts: 13,842
Re: ** Python Support Thread **

http://docs.python.org/library/pdb.html

My most common use case is just sticking:

import pdb
pdb.set_trace()

wherever I want to jump into the code.
jjshabado is offline   Reply With Quote
Old 06-10-2011, 01:02 PM   #58
Carpal \'Tunnel
 
tyler_cracker's Avatar
 
Join Date: Apr 2005
Location: Shallow End OTKP
Posts: 15,800
Re: ** Python Support Thread **

ok am i losing my mind, or is this behavior just absurdly retarded?

(yes, i appreciate the irony of my printf debugging considering the above discussion, but i'm trying to demonstrate a point.)

Code:
#!/usr/bin/env python

list = [1, 'a', 'b', 'c', 4]
for item in list:
    print "list before: %s" % list
    try:
        item = int(item)
    except ValueError:
        print "%s cannot be cast to int. Delete it." % item
        list.remove(item)
    else:
        print "%s looks like an int. No problem, mon." % item
    print "list after : %s" % list
    print

print "### final list is %s" % list
seems straightforward to me. however...

Spoiler:


is there some simple workaround to this problem? do i need to make a separate clone of list for purposes of iterating? ugh, python.
tyler_cracker is offline   Reply With Quote
Old 06-10-2011, 01:08 PM   #59
King of the sidebar
 
Neil S's Avatar
 
Join Date: Sep 2004
Location: Northern Virginia
Posts: 16,431
Re: ** Python Support Thread **

Messing with a list while you iterate through it is generally a bad idea, and that's not python-specific.
Neil S is offline   Reply With Quote
Old 06-10-2011, 01:15 PM   #60
Carpal \'Tunnel
 
tyler_cracker's Avatar
 
Join Date: Apr 2005
Location: Shallow End OTKP
Posts: 15,800
Re: ** Python Support Thread **

i mean, sure, i guess. i guess i don't know enough about how python handles its iterators internally to have an expectation that this would work.

that said, i feel like this pattern works fine in other languages. maybe i'm just losing my mind, as alluded to in my previous post .

edit: adding list_copy = copy.deepcopy(list) and iterating on that seems to solve the problem. i think the real solution is to use map/apply/whatever-the-****-python-calls-it with a lambda or small function, but i don't think it will greatly improve efficiency and it will probably hurt readability.
tyler_cracker is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -4. The time now is 08:50 PM.


Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.
Copyright 2008-2010, Two Plus Two Interactive