Author Topic: Anyone use Python?  (Read 15803 times)

Mike

  • Jackass In Charge
  • Posts: 11248
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Anyone use Python?
« Reply #15 on: February 16, 2012, 01:50:44 PM »
-Ken- do you know of any good python libraries that let me make some simple GUIs?  Need to expand some command line tools to do some file selection and such.  Mainly checkboxes, radio lists, and buttons.

I toyed with the wx library once upon a time, but I'm not qualified to make a recommendation one way or the other. Unless I'm toying around on the iPhone, I either write CLI or HTML. Not to sound too trendy, but TileMill is written in Node and HTML, and I would bet most people think it's a native application. http://mapbox.com/tilemill/

Perhaps you could just write a simple, self-contained HTML-based frontend.
Thanks, I'll take a look.  I need the program to run as a particular linux/mac user so using a webserver is out (we tried).  Part of what we are doing is doing svn commands so file ownership becomes a big pain.

-KEN-

  • Some Other Mofo
  • Jackass In Charge
  • Posts: 1001
  • Karma: +75/-100
Re: Anyone use Python?
« Reply #16 on: February 16, 2012, 02:13:27 PM »
Thanks, I'll take a look.  I need the program to run as a particular linux/mac user so using a webserver is out (we tried).  Part of what we are doing is doing svn commands so file ownership becomes a big pain.


Node can run as its own self-contained web server (the TileMill code is open source and on Github); python can actually do the same. We frequently create quick Django apps for data entry around here. It's nice, because anyone in the VPN can access it via the IP, and updates made to the server are instant for everyone.

If you created a quick django app, you would just need to run `python manage.py runserver 0.0.0.0:8000` from that user account, and anyone accessing the IP will make changes owned by the account you ran the command from.

Django is a huge framework though. You could check out Flask - http://flask.pocoo.org/. Very stripped down and much easier to write a small app in. You'd basically just write a route that showed the control panel at a URL (like '/'), and another one that accepts GET or POST input from the form and figures out what commands to execute locally.

JaWiB

  • definitelys definately no MacGyver
  • Jackass V
  • Posts: 1443
  • Karma: +57/-4
Re: Anyone use Python?
« Reply #17 on: February 16, 2012, 02:13:56 PM »
I was reading about properties and the guy wrote this:
Code: [Select]
@Property
    def name():
        doc = "The person's name"
#...
What's the deal with the doc= line? I thought you were supposed to use triple quotes for docstrings: """The person's name"""

Mike

  • Jackass In Charge
  • Posts: 11248
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Anyone use Python?
« Reply #18 on: February 16, 2012, 02:15:22 PM »
Thanks -Ken-.  Hopefully, once I get these current projects done I'll have more time to check that out.

-KEN-

  • Some Other Mofo
  • Jackass In Charge
  • Posts: 1001
  • Karma: +75/-100
Re: Anyone use Python?
« Reply #19 on: February 16, 2012, 02:21:52 PM »
I was reading about properties and the guy wrote this:
Code: [Select]
@Property
    def name():
        doc = "The person's name"
#...
What's the deal with the doc= line? I thought you were supposed to use triple quotes for docstrings: """The person's name"""

If he's using that and a capital P on @property, I wouldn't recommend listening to him. I've never seen that before; and furthermore, doc is represented by __doc__, not 'doc', so I don't think that even works.

JaWiB

  • definitelys definately no MacGyver
  • Jackass V
  • Posts: 1443
  • Karma: +57/-4
Re: Anyone use Python?
« Reply #20 on: February 16, 2012, 02:22:48 PM »

-KEN-

  • Some Other Mofo
  • Jackass In Charge
  • Posts: 1001
  • Karma: +75/-100
Re: Anyone use Python?
« Reply #21 on: February 16, 2012, 02:25:11 PM »
Yeah, that just plain doesn't work.

Code: [Select]
>>> def stuff():
...   doc="junk"
...
>>> stuff.__doc__
>>> def stuff():
...   __doc__ = "junk"
...
>>> stuff.__doc__
>>> def stuff():
...   print "OK"
...
>>> stuff.__doc__ = "This prints 'OK'"
>>> stuff.__doc__
"This prints 'OK'"
>>> def junk():
...   """
...    this does nothing.
...   """
...   pass
...
>>> junk.__doc__
'\n   this does nothing.\n  '

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4635
  • Karma: +64/-22
    • http://jeff.bagu.org
Re: Anyone use Python?
« Reply #22 on: February 16, 2012, 08:17:42 PM »
I was reading about properties and the guy wrote this:
Code: [Select]
@Property
    def name():
        doc = "The person's name"
#...
What's the deal with the doc= line? I thought you were supposed to use triple quotes for docstrings: """The person's name"""

Triple quotes are just for multi-line strings in general. You can use them anywhere, not just for the __doc__ string.

-KEN-

  • Some Other Mofo
  • Jackass In Charge
  • Posts: 1001
  • Karma: +75/-100
Re: Anyone use Python?
« Reply #23 on: February 17, 2012, 06:42:59 PM »
Yeah, but you can't just write doc="string" inside of a function. You're just creating a local variable; it has nothing to do with __doc__

JaWiB

  • definitelys definately no MacGyver
  • Jackass V
  • Posts: 1443
  • Karma: +57/-4
Re: Anyone use Python?
« Reply #24 on: February 27, 2012, 02:41:44 PM »
Either of you guys use eclipse? Is there a way to debug using the interactive console?

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: Anyone use Python?
« Reply #25 on: February 27, 2012, 02:58:27 PM »
I've tried using elcipse a couple times in the past. Before, as an alternative to dreamweaver because I just wanted a free IDE with sytax highlighting, and most recently because all of the phonegap tutorials basically force you to use it.*  In both instances I've become fairly frustrated with the UI and the processess for setting up the coding environment on each project. In otherwords, I have no idea how to debug with it, sorry :)


*of course, now that adobe has bought phonegap, its integrated into Dreamweaver CS 5.5+ so I guess that the deal breaker to keep me on their platform.

"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: Anyone use Python?
« Reply #26 on: February 27, 2012, 03:31:05 PM »
We use Eclipse where I work.  But that's for Java.  And the debug view is fucking amazing.  I really like Eclipse for what I do at work but I think it's too much bloat for some of my personal projects.

JaWiB

  • definitelys definately no MacGyver
  • Jackass V
  • Posts: 1443
  • Karma: +57/-4
Re: Anyone use Python?
« Reply #27 on: February 27, 2012, 04:52:07 PM »
I've come to like eclipse since I can use it for basically any language I want. The debugger works fine, but I'd like to take advantage of the fact that I can run any function without compiling anything and be able to step through whatever I call using the debugger. The easiest way I've found is just to write a little debug python script and then hit Run->Debug with that file open. Seems fine  :dunno:

Now I'm wondering how to write code that only executes in debug mode, like I'd do in C++:
Code: [Select]
#ifdef DEBUG
//...
#endif
Not sure that even makes sense though since it isn't compiled. Basically I want to be able to switch on and off communication with the hardware so I can test the rest of the code before trying to actually control the instrumentation.

JaWiB

  • definitelys definately no MacGyver
  • Jackass V
  • Posts: 1443
  • Karma: +57/-4
Re: Anyone use Python?
« Reply #28 on: February 27, 2012, 05:39:42 PM »
While I'm at it, what are your conventions for naming files and classes? I'm finding it cumbersome to name a file "ls331.py" and have a class named "LS331" now I have:
Code: [Select]
from instruments import ls331
#...
ls331.LS331.foo()
I could use "import ls331 as tc" or something but then what do I call the instances of the class?

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4635
  • Karma: +64/-22
    • http://jeff.bagu.org
Re: Anyone use Python?
« Reply #29 on: February 27, 2012, 09:40:58 PM »
you can also use "from ls331 import LS331"