Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
digitalcamo
Jul 11, 2013
I'm currently in my second week of learning how to program in Python using Learn Python The Hard Way. So far I understand all the code that is thrown at me. Should I use more than one learning source or multiple? I've had several people tell me that you need to be learning by getting started on a big project you want to do. How am I suppose to start a big project and don't even know how to program. This my first programming language by the way. And I want to learn how to program, not learn how to program a big project and that's all I learn to do.

Adbot
ADBOT LOVES YOU

duck monster
Dec 15, 2004

Suspicious Dish posted:

I actually recommend you check out JS. For all you may have heard otherwise, it's actually fairly Python-like and I often feel like I'm writing Python in JavaScript.

That said, I tend to use Mozilla JS in most of my projects which gives me fun stuff like destructuring assignment, let, and list comprehensions / generator expressions:

JavaScript code:
let foo = ["a", {"b": "c"}, "d"];
let [a, {"b": c}, d] = foo;

let bar = [x*2 for (x of [1,2,3,4,5])];
for (let a of bar)
    print(a);

Yeah and then it goes and does something stupid like telling you that 2 + 2 = 22 requiring one to bounce a chair off a wall in a fit of rage. Its a pale immitation at best, albeit one with some neat chops for closures and prototype OO

WeezerToon
Sep 25, 2011

digitalcamo posted:

I'm currently in my second week of learning how to program in Python using Learn Python The Hard Way. So far I understand all the code that is thrown at me. Should I use more than one learning source or multiple? I've had several people tell me that you need to be learning by getting started on a big project you want to do. How am I suppose to start a big project and don't even know how to program. This my first programming language by the way. And I want to learn how to program, not learn how to program a big project and that's all I learn to do.

Hello fellow python 2nd-weeker! I've been following a beginners book along side using codecademy and I've found that the web learning is pretty good as a supplement, I'd recommend it.

Nimrod
Sep 20, 2003

digitalcamo posted:

I'm currently in my second week of learning how to program in Python using Learn Python The Hard Way. So far I understand all the code that is thrown at me. Should I use more than one learning source or multiple? I've had several people tell me that you need to be learning by getting started on a big project you want to do. How am I suppose to start a big project and don't even know how to program. This my first programming language by the way. And I want to learn how to program, not learn how to program a big project and that's all I learn to do.

Considering you're only in your second week, i'd recommend a small project over a big one. But it is definitely good to have something outside of just the practice examples in a a book. If you can't think of any ideas, there's always these ones:

http://www.python-forum.org/viewtopic.php?f=10&t=378

digitalcamo
Jul 11, 2013
Which book are you following? I have looked at codecadmy and liked what I saw. And unfortunately like I do everything I looked to see what other people thought about it. Most of what I read about codecadmy was negative. But that might have been the opinions of programmers that believe they know everything. I might give that site a shot. I would like to think any resource I can get my hands on would be beneficial either way.

Dominoes
Sep 20, 2007

digitalcamo posted:

I'm currently in my second week of learning how to program in Python using Learn Python The Hard Way. So far I understand all the code that is thrown at me. Should I use more than one learning source or multiple? I've had several people tell me that you need to be learning by getting started on a big project you want to do. How am I suppose to start a big project and don't even know how to program. This my first programming language by the way. And I want to learn how to program, not learn how to program a big project and that's all I learn to do.
I learned to program from Codeacademy's Python tutorial, with lots of help from this thread. The interactive nature of the tutorial made it fun and easy to learn. Whenever you'd like (even if you haven't finished the book/tutorial), get started on a project you'd like to do, even if it seems ambitious for a beginner.

Gnumonic
Dec 11, 2005

Maybe you thought I was the Packard Goose?

digitalcamo posted:

I'm currently in my second week of learning how to program in Python using Learn Python The Hard Way. So far I understand all the code that is thrown at me. Should I use more than one learning source or multiple? I've had several people tell me that you need to be learning by getting started on a big project you want to do. How am I suppose to start a big project and don't even know how to program. This my first programming language by the way. And I want to learn how to program, not learn how to program a big project and that's all I learn to do.

I'm probably two weeks ahead of you in my Python/programming adventure, and I've been alternating between Learn Python the Hard Way and the Udacity CS101 course. I feel like they complement each other pretty well - the Udacity course is pretty bad having you get really familiar with the concepts it introduces, but I don't think I would have gotten a decent grasp on classes (and especially inheritance) without having it explained to me in small bites. I might be a little biased towards things that function like university courses though, since I'm a humanities grad student and I'm better at structured learning. Over the course of the Udacity course you design a rudimentary search engine, which helped me see how "real" (parts of it are pretty contrived but whatever) programs get made. The instructor is also really good, I'd at least check it out and see if it works for you.

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
I learned from Think Python and I feel like this is a book that should deserve far more praise than The Hard Way.

I also like how it seems to be always changing and updating things (back when I read it was called How to Think Like a Computer Scientist)

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Symbolic Butt posted:

I learned from Think Python and I feel like this is a book that should deserve far more praise than The Hard Way.

I also like how it seems to be always changing and updating things (back when I read it was called How to Think Like a Computer Scientist)

I agree with this. Not that Hard Way is bad, but I like Think Python more.

Anyway, I typed up a list like this in this thread years ago, but off the top of my head, here's some projects a beginner might like to tackle:

  • Organize the files in your downloads directory.
  • A script to tell you when a web page changes.
  • Duplicate file finder.
  • An IRC bot.
  • A random wallpaper chooser.
  • A twitter feed checker.
  • Organize photos by date/camera/colors/exif/whatever.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

duck monster posted:

Yeah and then it goes and does something stupid like telling you that 2 + 2 = 22 requiring one to bounce a chair off a wall in a fit of rage. Its a pale immitation at best, albeit one with some neat chops for closures and prototype OO

There's only a few times that a bug like that has bit me, and I've never felt rage like that. "use strict"; (which is on by default in the JS framework we wrote) handles most of the bigger annoyances.

digitalcamo
Jul 11, 2013
Well I'll try out Think Python too and see how that is. And the program ideas for a beginner you listed, I don't even know where I would start with that. Are those programs I should at least have an idea on where to start? So far I've only learned about Variables, learning Functions right now, printing, and a little bit of importing. But, I don't know maybe it will all just click one day like anything else you learn. I'm anxious to start making programs that look like a program and not something I have to type into a command line. Or is that how all Python programs are? I'm hoping I'm on track with my learning because learning how to program is definitely something I have to learn how to do.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

digitalcamo posted:

Well I'll try out Think Python too and see how that is. And the program ideas for a beginner you listed, I don't even know where I would start with that.

That's kind of the idea with tackling projects as a beginner. Inevitably, you'll not know how to do something so you go figure out how to do it.

Like, think about the project to organize files in your downloads directory. You'll need to know how to get a list of files in a directory, so google "python list files in directory". Be sure to read more than one source, because there will inevitably be people recommending stupid things.

digitalcamo posted:

Are those programs I should at least have an idea on where to start? So far I've only learned about Variables, learning Functions right now, printing, and a little bit of importing.

It's still early days for you, just keep plugging along.


digitalcamo posted:

But, I don't know maybe it will all just click one day like anything else you learn. I'm anxious to start making programs that look like a program and not something I have to type into a command line. Or is that how all Python programs are?

What you're talking about is a a program with a GUI. A program that involves you typing at the command line is just as much a program as something with a graphical user interface.

A GUI is a more advanced thing to do, but you can definitely make them with Python. There is some advanced, complicated GUI programs out there written in Python. However, depending on who the audience for your programs are, you'll likely find yourself less and less worried about whether or not you have to type something at the command line.

digitalcamo
Jul 11, 2013
Well I didn't know if looking up how to do this or do that in a program would be considered cheating and being lazy. Wasn't sure if that's a good way to learn or if I should be able to figure it out myself. Guess that is a little ignorant way of thinking though because I didn't simply figure out how to do electric work, someone had to teach me how to bend pipe, how to make up this motor or transformer so it doesn't blow up. Guess the same thing applies to learning how to program.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

digitalcamo posted:

Well I didn't know if looking up how to do this or do that in a program would be considered cheating and being lazy. Wasn't sure if that's a good way to learn or if I should be able to figure it out myself. Guess that is a little ignorant way of thinking though because I didn't simply figure out how to do electric work, someone had to teach me how to bend pipe, how to make up this motor or transformer so it doesn't blow up. Guess the same thing applies to learning how to program.

Well, maybe some programmers are able to figure stuff out from the first principles of computing, but to the rest of us Google is a godsend.

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

A python IRC bot is what made me finally "get" programming after having messed around in various languages for years.

digitalcamo
Jul 11, 2013
Well didn't take long for me to get confused about functions.

def do_twice(f, arg):
f(arg)
f(arg)

def print_twice(arg):
print arg
print arg

do_twice(print_twice, 'spam')
print ''

I understand that arg gets replaced with 'spam' but why does it print spam four times? Seems like it should only print twice.

Why would it not be print f (arg)?

Emacs Headroom
Aug 2, 2003
1) Use code tags:
Python code:
def do_twice(f, arg):
    f(arg) 
    f(arg)

def print_twice(arg):
    print arg
    print arg

do_twice(print_twice, 'spam')
2) You're calling "print_twice" twice, through do_twice. 2x2=4, so it prints 4 times (twice, twice).

Dominoes
Sep 20, 2007

Well, I had no idea you could pass functions as arguments.

digitalcamo
Jul 11, 2013
How do you usually pass functions? That code is from the Think Python book. The examples in Learn Python The Hard Way are a little bit different and a little easier to understand. But I like seeing how other people do it.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

digitalcamo posted:

How do you usually pass functions? That code is from the Think Python book. The examples in Learn Python The Hard Way are a little bit different and a little easier to understand. But I like seeing how other people do it.

That's how you do it.

I think Dominoes is just saying he didn't know you could do it at all. Being able to pass a function to a function isn't a necessary requirement to being able to write programs, so I can see how someone fairly new (IIRC, you're fairly new, Dominoes...I hope I'm not putting my foot in my mouth!) wouldn't realize it was A Thing You Can Do.

It's kind of a fundamental part of the way Python works, though.

Emacs Headroom
Aug 2, 2003

digitalcamo posted:

How do you usually pass functions? That code is from the Think Python book. The examples in Learn Python The Hard Way are a little bit different and a little easier to understand. But I like seeing how other people do it.

Exactly the way you did it. I believe that functions are just objects in Python (as in I think you can just make a class that has a __call__ method and it's a function). You can pass objects to functions, so there's no reason you can't pass objects that are also functions.

Another functional thing that's useful is closures, where you can save some state along with your function. Here's a contrived example:

Python code:
def make_multiplier(n):
    def mult(x):
        return x*n
    return mult

doubler = make_multiplier(2)
tripler = make_multiplier(3)

doubler(10) #20
doubler(20) #40
tripler(3) #9

Dominoes
Sep 20, 2007

Thermopyle posted:

That's how you do it.

I think Dominoes is just saying he didn't know you could do it at all. Being able to pass a function to a function isn't a necessary requirement to being able to write programs, so I can see how someone fairly new (IIRC, you're fairly new, Dominoes...I hope I'm not putting my foot in my mouth!) wouldn't realize it was A Thing You Can Do.

It's kind of a fundamental part of the way Python works, though.
Figured all the noob questsions I post here would be a dead giveaway! Thanks Digitalcamo you just opened a new door for me.

e: Nested functions too. :psyduck:

Dominoes fucked around with this message at 03:42 on Jul 31, 2013

etcetera08
Sep 11, 2008

This is because functions are "first class" in Python. For more information: http://en.wikipedia.org/wiki/First-class_function

It's neat.

FoiledAgain
May 6, 2007

I'm having trouble understanding how to get a thread to stop running. It appears from some googling that there's no general way to do this (i.e. no such thing as thread.quit()). In my case, I have a simulation GUI (written with Tkinter) and I want the user to be able to click a "cancel" button if they need to stop a simulation for some reason. How do I accomplish this?

I set it up so that clicking the button sets stop_thread to True. This in turn is supposed to cause a change in a similar variable inside the simulation, which results in the simulation calling sys.exit(). But nothing actually happen. The simulation keeps on running until it's finished, as though the change in variable is not happening. What's the correct way to communicate between threads here?

Psuedo-code:

code:

def run_simulation(self):
	self.simulation = sim_tools.Simulation()
	self.secondary_thread = threading.Thread(target=self.simulation.main)
        self.stop_thread = False#set to true when user clicks a "Cancel" button
        self.secondary_thread.start()
        self.after(500, self.check_thread)

def check_thread(self):

        if self.secondary_thread.is_alive():
            if self.stop_thread:#if user clicked a cancel button
                self.simulation.stop_simulation = True #this appears to have no effect

            self.after(300, self.check_thread)
        else:
            tkMessageBox.showinfo('Complete', 'Simulation is complete.')

evensevenone
May 12, 2001
Glass is a solid.
Use a threading.Event object. It does basically what you are trying to do, but it will actually work.

FoiledAgain
May 6, 2007

evensevenone posted:

Use a threading.Event object. It does basically what you are trying to do, but it will actually work.

I read about these, but I don't really get how they work. (I've been working with threading for maybe three days nows, so not everything is clear yet.) I assume that I want to set the Event flag to True when the user clicks the cancel button, but then I'm in the same place of not knowing how to communicate this information to the other thread.

FoiledAgain fucked around with this message at 09:05 on Jul 31, 2013

WeezerToon
Sep 25, 2011
Could you use a while statement with a break statement, or is that too simplistic in this context?

The March Hare
Oct 15, 2006

Je rêve d'un
Wayne's World 3
Buglord
Am I making things hard on myself by using X11 to hook keyboard input to monitor for global key presses on Ubuntu? I basically just need this script to run in the background and call one function when I press ctrl+c and another when I press ctrl+v. I got it working in Windows using pythoncom and pyhook, but Linux is a bit tougher than that.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
May I ask exactly what your program wants to do here? I assume something to do with the clipboard? It's likely there are simpler ways under X11, because X11 can't snoop key events globally.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

duck monster posted:

That I doubt. Cocos2d for ios has the lionshare of the market, is conceptually multiplatform via cocos2s-x and its html5 spin-off and has zynga as the 700lb gorilla backing it.

Apple could make a big impact by bringing scene kit across to the ipad which would pull the rug out from cocos2d feet by delivering proper 3d, (There is cocos3d but its a bit of a mess and doesnt support shaders making it pretty ancient and lovely), but at the moment gamekit is the minority platform for the iphone right now. Its not widely used, hasn't the tooling cocos2d has, nor is it as capable. Or as easy actually.

Cocos2d python is very nice by the way.

Zynga is dying fast,but that's besides the point. For iOS (again, I'm being specific to iOS here) cocos2D is going to all but vanish. This does not mean cocos2D is going away. I was pointing out that it's heavy focus on iOS will be going away most likely, as that was one of the original poster's concerns: that so much of it's tutorials / samples were iOS related. I'm simply pointing out that the focus of cocos2D will shift away from iOS, and has been slowly for a little while, but that trend will accelerate since Apple's new 2D game API will likely be getting a large dev mind-share in iOS-land.

evensevenone
May 12, 2001
Glass is a solid.

FoiledAgain posted:

I read about these, but I don't really get how they work. (I've been working with threading for maybe three days nows, so not everything is clear yet.) I assume that I want to set the Event flag to True when the user clicks the cancel button, but then I'm in the same place of not knowing how to communicate this information to the other thread.

The other thread can check the state of the event with is_set(). So it would basically just replace that simulation.stop_thread Boolean.

MeruFM
Jul 27, 2010
I want a lightweight graphing library to integrate with wxPython that can do simple but nice looking and fast 2D line graphs that allows the user to pan and zoom.
Matplotlib is okay but it's very heavy and slow. The annotation support is nice though.

If there's no library like this existing, would it be better to make one in PyGame or some kind of canvas?
My requirement is only a simple 2D line graph with 500-5k data points. Just want lots of control over the design of it.

I have minimal desktop GUI experience, but some frame drawing experience via XNA, processing, and html5 canvas.

OnceIWasAnOstrich
Jul 22, 2006

MeruFM posted:

I want a lightweight graphing library to integrate with wxPython that can do simple but nice looking and fast 2D line graphs that allows the user to pan and zoom.
Matplotlib is okay but it's very heavy and slow. The annotation support is nice though.

If there's no library like this existing, would it be better to make one in PyGame or some kind of canvas?
My requirement is only a simple 2D line graph with 500-5k data points. Just want lots of control over the design of it.

I have minimal desktop GUI experience, but some frame drawing experience via XNA, processing, and html5 canvas.

Chaco? Relatively simple to make 2D plots, interactive, integrates with wxPython.

MeruFM
Jul 27, 2010

OnceIWasAnOstrich posted:

Chaco? Relatively simple to make 2D plots, interactive, integrates with wxPython.

Thanks. Is there an easier way to install this than do infinite recurse package installation?
I tried installing with easy_install which gives me a trait.api error so i install traits and I get an enable.api error and I try to install enable and I get a swig error which is not a python package?

I tried installing the EDP https://www.enthought.com/products/epd/free/, but apparently it's now the Canopy Express standalone python distribution instead of just a package?

Wow.

salisbury shake
Dec 27, 2011

MeruFM posted:

I want a lightweight graphing library to integrate with wxPython that can do simple but nice looking and fast 2D line graphs that allows the user to pan and zoom.
Matplotlib is okay but it's very heavy and slow. The annotation support is nice though.

If there's no library like this existing, would it be better to make one in PyGame or some kind of canvas?
My requirement is only a simple 2D line graph with 500-5k data points. Just want lots of control over the design of it.

I have minimal desktop GUI experience, but some frame drawing experience via XNA, processing, and html5 canvas.

Have you checked out sage? It has multiple backends and has been incredibly fast and easy to use for my needs.

Reference for 2D plotting: http://www.sagemath.org/doc/reference/plotting/

Some cool poo poo that probably is completely irrelevant for your needs: http://wiki.sagemath.org/pics and http://www.sagemath.org/tour-graphics.html

edit: further investigation yields that sage uses matplotlib for 2D graphing, so this might be a moot point

salisbury shake fucked around with this message at 23:04 on Jul 31, 2013

DSA_Key
Dec 9, 2004
minimalist
So I needed something that could execute commands on multiple Linux systems and bring the data back to me for parsing. So using Python and Pexpect I wrote the following and I just wanted to share as this is the very first project I've ever undertaken in Python let alone Pexpect. The only thing the script doesn't ask for is the file with the IP addresses or hostnames instead it's hard coded to read a targets.txt file in the directory it's executed from.

Eventually I'll update it so it has a help function and ask for a custom file with a list of hosts and maybe sanitize user input etc.... But I was stoked I got this far and I just want to share! Python's pretty cool.

edit* also it writes an error log with a best guess as to why it couldn't log into a server.

code:
#!/usr/bin/python

import pexpect
import os
import sys
import getpass
import time

#Define main function for looping though the hostnames
def main(): 



  #Variables
  username = getusername()
  COMMAND = getcommand()
  password = getpass.getpass()
  DENIED = 'denied'
  PROMPT = '[#\$] '
  LIVEPROMPT = '\$'    #Some servers have colored prompts to indicate they are live servers this regex looks for those
  REFUSED = 'refused'
  
  
  #Lists
  hosts=[]

  #Open file for reading hostnames, should be return deliniated
  with open('targets.txt') as f:
    data = f.read()
  f.close()

  #Splits hostnames or host ip addresses into the list hosts
  hosts = data.split('\n')


  for host in hosts:  #This is the loop that runs through the list of hosts in your file

    if host != "":    #Check for null host in list, happens at blank return lines

      #Create the connections string  we are going to use to SSH to the host 
      connectstring = 'ssh -o StrictHostKeyChecking=no %s@%s' %(username,host,)

      #Use pexpect to spawn the SSH connection to the host
      session = pexpect.spawn (connectstring)

      #Give some feedback to the user as to where we are in teh list
      print 'Connecting to %s.......' %(host,)

      #Check our spawned session to see what SSH gave back to us - looking for an SSH session timeout,
      #or a Prompt (can happen if an SSH keypair was setup before hand), or the password prompt, we 
      #could be denied or refused right away
      i = session.expect ([pexpect.TIMEOUT, PROMPT, '[Pp]assword:', DENIED, REFUSED])

      if i == 0:
        
        #If we get timed out we write the error and close the session and continue the for loop
        error = '%s : Host timed out could be dead! \n' %(host,)
        writeerror(error, session)
        continue
        
      if i == 1:
      
        #If we end up at the prompt we just pass to the next check to run the commands
        pass
        
      if i == 2:

        #If we get a password prompt we wait a half second because in some cases we aren't 
        #matching the space at the end
        time.sleep(0.5) 
        #Once we're good we send the password to the session
        session.sendline(password)
        
      if i == 3:
        
        #We got denied from the host right away, possible network problem IPtables maybe?
        error = '%s : Permission Denied at first login attempt \n' %(host,)
        writeerror(error, session)
        continue
      
      if i == 4:

        #We got refused by the server it didn't like us 
        error = '%s : Connection Refused by Server \n' %(host,)
        writeerror(error, session)
        continue
    
      #We sent the password, so we have to check if we are at the prompt or if our password didn't work
      #and we are being prompted again
      j = session.expect([PROMPT, LIVEPROMPT, '[Pp]assword:'])
    
      if j == 0:

        #YAY! we are at the prompt we can send the command!!!!!! Calls function copycommand!!      
        copycommand(session, host, COMMAND)
    
      if j == 1:

        #YAY! command prompt! Call the copycommand function!!!!
        copycommand(session, host, COMMAND)
    
      if j == 2:

        #Maybe we have a bad password or a bad username cause we got stuck at the password prompt
        time.sleep(0.5)
        error = '%s : Bad Password or Username \n' %(host,)
        writeerror(error, session)
        continue
        
        

#If we make it to a command prompt on a remote host this fuction will run the command the user entered
#then write the output of the session to a logfile.
def copycommand(session, host, COMMAND):

  print "Sending Command: %s to Host: %s" %(COMMAND, host) #User feedback
  spacer = '\n \n --------%s-------- Command: ' %(host,)  #Spacer for the command outputs to the logfile
  fout = file ('logfile.txt', "ab") #Setup the file we are going to write to.
  fout.write(spacer)  #Write out the spacer
  session.sendline (COMMAND)  #Send the user command to the ssh session
  #Our linux command prompts start with "[" so we use that as an endpoint for the previous command then
  session.expect ('\[', timeout=None)
  #We write out the previous command with the .before method from pexpect
  fout.write(session.before)
  #Write out some whitespace to make the log more readable
  fout.write('\n \n')
  fout.close()                #close file and exit session.
  session.sendline('exit')
  

def writeerror(error, session):  #Open a file for error writing and echo in the errors we might have gotten

  print error  
  errorout = file('errors.txt', "ab")
  errorout.write(error)
  errorout.close()
  session.kill(0)
  

#####Functions for getting user input-
def getusername():

  username = raw_input("Enter Username: ")
  return username
  

def getcommand():

  command = raw_input("Enter Command: ")
  return command  
######  
  
if __name__ == "__main__":
    main()
    
print 'Commands Complete! Grats!'



FoiledAgain
May 6, 2007

evensevenone posted:

The other thread can check the state of the event with is_set(). So it would basically just replace that simulation.stop_thread Boolean.

It works perfectly now. Thanks!

The March Hare
Oct 15, 2006

Je rêve d'un
Wayne's World 3
Buglord

Suspicious Dish posted:

May I ask exactly what your program wants to do here? I assume something to do with the clipboard? It's likely there are simpler ways under X11, because X11 can't snoop key events globally.

Yeah sure, I'm just making a small script to monitor my different computers for copy/paste events in order to enable a big shared clipboard and clipboard history through a django app. I've got the django app built with a little API all set up to handle the clipboard data, and I basically want the script to globally monitor for key combinations. On ctrl+c I want it to take the data currently in the clip board and blip it on over to the django app, and then on a separate keypress (not actually ctrl+v) I would like it to pull down the most recent entry under a certain user from the django app and store that information to the clipboard.

I've got all of the rest of this stuff working, the Django app is built, I've got clipboard reading and writing working across osx, ubuntu, and windows and I have global keyboard monitoring working on windows -- but osx and ubuntu are a bit tougher to do it on since they are real operating systems.

I had found some code that used xlib that seems like it might work, but if you are saying that it can't hook globally then I guess I should ask for an opinion on a solution that will work.

BigRedDot
Mar 6, 2008

MeruFM posted:

Thanks. Is there an easier way to install this than do infinite recurse package installation?
I tried installing with easy_install which gives me a trait.api error so i install traits and I get an enable.api error and I try to install enable and I get a swig error which is not a python package?

I tried installing the EDP https://www.enthought.com/products/epd/free/, but apparently it's now the Canopy Express standalone python distribution instead of just a package?

Wow.

I used to work on chaco. It's not especially lightweight, it's geared towards interactive and high frequency streaming plotting. It depends on alot of other machinery as you have discovered.

As an alternative to EPD (since it is no longer available, AFAIK) I would suggest Anaconda, which is free and self-contained. Not sure if Chaco is part of the default install but if not just run "conda install chaco" afterwards and it will fetch chaco as well as any necessary dependencies for you. [disclaimer: I work for Continuum]

Adbot
ADBOT LOVES YOU

ahmeni
May 1, 2005

It's one continuous form where hardware and software function in perfect unison, creating a new generation of iPhone that's better by any measure.
Grimey Drawer
Part generic programming and part pythonic question:

I'm currently grinding through a weird project at work and reverse engineering a lovely piece of software through wireshark dumps. I have a bunch of data that I can only describe as "inverted hex"? I don't think it's an endian issue because array.byteswap doesn't give the same result.

code:

import struct
from array import array

a = '\x3e'
b = 255 - struct.unpack("B", a)[0]
print repr(struct.pack("B", b))
# result '\xc1' - correct

ar = array("B")
ar.fromstring(a)
ar.byteswap()
print repr(ar.tostring())
# result '>' - incorrect

Am I doing something wrong, and if not, what's the quickest way to perform the inversion on each byte in a string in Python?

  • Locked thread