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
Suspicious Dish
Sep 24, 2011

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

Bunny Cuddlin posted:

I know SDL supports it.

SDL supports DirectInput and the Windows Multimedia interface, but doesn't support XInput. How do you know that SDL "supports it"?

Adbot
ADBOT LOVES YOU

Bunny Cuddlin
Dec 12, 2004

Suspicious Dish posted:

SDL supports DirectInput and the Windows Multimedia interface, but doesn't support XInput. How do you know that SDL "supports it"?

Well





lol, I guess that's where I got the idea

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
All this is telling you is that the Xpad driver in the kernel is better than the DirectInput one.

Bunny Cuddlin
Dec 12, 2004

Suspicious Dish posted:

All this is telling you is that the Xpad driver in the kernel is better than the DirectInput one.

I was only explaining why I "knew" they could be treated by two different axes by SDL; I'd seen it in using my controller on my Linux dev machine. I see now that it is a DirectInput issue (which is even acknowledged by Microsoft here).

Sylink
Apr 17, 2004

Is there a good windows compatible module or method in Python for making live data tools?

I basically want to make something that consists of a list of items, with associated numbers that update using live information with text input to run basic commands.

Kind of like a curses app, I guess, but curses doesn't work on Windows and all the ports suck.

I looked at libtcod which was a roguelike module but it did not handle text fields easily.

Movac
Oct 31, 2012

Sylink posted:

Is there a good windows compatible module or method in Python for making live data tools?

I basically want to make something that consists of a list of items, with associated numbers that update using live information with text input to run basic commands.

Kind of like a curses app, I guess, but curses doesn't work on Windows and all the ports suck.

I looked at libtcod which was a roguelike module but it did not handle text fields easily.

If you don't need it to be in a console window, try Tkinter. It's a useful library for making simple GUIs, and it's part of the standard library.

Sylink
Apr 17, 2004

I might have to do something like that or even pygame.

I tried curses a bit and it almost does what I need but I want stuff to be running while entering input, while curses does everything in a step fashion so everything pauses while it waits for keypresses (since its just for utilities not super real time stuff, I'm not sure how roguelikes get around that, probably a different lib).

Bunny Cuddlin
Dec 12, 2004

Sylink posted:

I might have to do something like that or even pygame.

I tried curses a bit and it almost does what I need but I want stuff to be running while entering input, while curses does everything in a step fashion so everything pauses while it waits for keypresses (since its just for utilities not super real time stuff, I'm not sure how roguelikes get around that, probably a different lib).

most roguelikes operate on a step basis too

Cat Plus Plus
Apr 8, 2011

:frogc00l:

Sylink posted:

I tried curses a bit and it almost does what I need but I want stuff to be running while entering input, while curses does everything in a step fashion so everything pauses while it waits for keypresses (since its just for utilities not super real time stuff, I'm not sure how roguelikes get around that, probably a different lib).

You can poll for input without blocking. It's called no-delay mode.

Alligator
Jun 10, 2009

LOCK AND LOAF
if you're interested i also write stuff on this blog sometimes and i took that guy's code and wrapped in a simple class to play with a while ago.

https://gist.github.com/4035738

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I wonder if anybody here has tried to do a REST client in Python using the requests module in particular, but I generally have a flow control question. I am doing a streaming get, which looks to be designed to run forever if you let it. However, I'd like to be able to break out of it in the most proper, elegant way possible. Right now, I just break out of the loop processing it and that's that.

My gripes:
1. The streaming get is technically still going at the scope level I break out of
2. I don't know of a way to specify loop scope when I execute the break.

I'm doing something like this:
code:
get_status_request = requests.get("https://butts/stuff", auth=('RockoBonaparte', 'pantsbutts'), prefetch=False)

line_count = 0
for line in get_status_request.iter_lines():
    if line: # filter out keep-alive new lines
        line_count += 1
        print(line)
        if line_count >= 3:
            break
I was hoping there's a better way since this just doesn't smell right. One thing: I know the with keyword doesn't work on requests.get. There is not __exit__ clause. Otherwise I'd have a nice way to close up that request when I exit out of the for loop.

Captain Capacitor
Jan 21, 2008

The code you say?

Rocko Bonaparte posted:

I wonder if anybody here has tried to do a REST client in Python using the requests module in particular, but I generally have a flow control question. I am doing a streaming get, which looks to be designed to run forever if you let it. However, I'd like to be able to break out of it in the most proper, elegant way possible. Right now, I just break out of the loop processing it and that's that.

My gripes:
1. The streaming get is technically still going at the scope level I break out of
2. I don't know of a way to specify loop scope when I execute the break.

I'm doing something like this:
code:
get_status_request = requests.get("https://butts/stuff", auth=('RockoBonaparte', 'pantsbutts'), prefetch=False)

line_count = 0
for line in get_status_request.iter_lines():
    if line: # filter out keep-alive new lines
        line_count += 1
        print(line)
        if line_count >= 3:
            break
I was hoping there's a better way since this just doesn't smell right. One thing: I know the with keyword doesn't work on requests.get. There is not __exit__ clause. Otherwise I'd have a nice way to close up that request when I exit out of the for loop.

Looks like requests has an Session object supports __exit__ and a close method, and can be passed as the 'session' kwarg.

Drunk Badger
Aug 27, 2012

Trained Drinking Badger
A Faithful Companion

Grimey Drawer
I'm making a serious attempt at learning Python, so I'm looking for a good Python IDE. The only other IDE I have good experience with is Visual Studio for a C# and C++ class, pop up tips and the ability to set break points with a nice list of variables and their values are probably the two things that helped the most in learning those, and as a novice programmer, probably things I require to hold my hand as I get into Python.

After looking at the IDE list I see that Spyder looks like a decent choice, the only downside is that it looks like it only supports Python 2, and I'd like to stick with version 3.

So my questions are:

1. Is there a Python 3 IDE that contains breakpoints and pop up hints?

2. Is it a terrible idea to use version 2 and Spyder instead of version 3 and some possibly lesser IDE?

Bunny Cuddlin
Dec 12, 2004

Alligator posted:

if you're interested i also write stuff on this blog sometimes and i took that guy's code and wrapped in a simple class to play with a while ago.

https://gist.github.com/4035738

This is cool, thank you. I ended up doing XInput calls whenever I got an event for axis 2 and keeping track of previous values for each axis in order to decide which one was pressed. I wanted to monkey-patch it into the Joystick object in pygame but you can't modify objects from extension code at runtime :eng99:

Titan Coeus
Jul 30, 2007

check out my horn

Drunk Badger posted:

I'm making a serious attempt at learning Python, so I'm looking for a good Python IDE. The only other IDE I have good experience with is Visual Studio for a C# and C++ class, pop up tips and the ability to set break points with a nice list of variables and their values are probably the two things that helped the most in learning those, and as a novice programmer, probably things I require to hold my hand as I get into Python.

After looking at the IDE list I see that Spyder looks like a decent choice, the only downside is that it looks like it only supports Python 2, and I'd like to stick with version 3.

So my questions are:

1. Is there a Python 3 IDE that contains breakpoints and pop up hints?

2. Is it a terrible idea to use version 2 and Spyder instead of version 3 and some possibly lesser IDE?

I've always liked PyDev http://pydev.org/

Captain Capacitor
Jan 21, 2008

The code you say?

Drunk Badger posted:

I'm making a serious attempt at learning Python, so I'm looking for a good Python IDE. The only other IDE I have good experience with is Visual Studio for a C# and C++ class, pop up tips and the ability to set break points with a nice list of variables and their values are probably the two things that helped the most in learning those, and as a novice programmer, probably things I require to hold my hand as I get into Python.

After looking at the IDE list I see that Spyder looks like a decent choice, the only downside is that it looks like it only supports Python 2, and I'd like to stick with version 3.

So my questions are:

1. Is there a Python 3 IDE that contains breakpoints and pop up hints?

2. Is it a terrible idea to use version 2 and Spyder instead of version 3 and some possibly lesser IDE?

Full discretion, I know these guys: PTVS

I'm not sure about version support.

raminasi
Jan 25, 2005

a last drink with no ice

Drunk Badger posted:

I'm making a serious attempt at learning Python, so I'm looking for a good Python IDE. The only other IDE I have good experience with is Visual Studio for a C# and C++ class, pop up tips and the ability to set break points with a nice list of variables and their values are probably the two things that helped the most in learning those, and as a novice programmer, probably things I require to hold my hand as I get into Python.

After looking at the IDE list I see that Spyder looks like a decent choice, the only downside is that it looks like it only supports Python 2, and I'd like to stick with version 3.

So my questions are:

1. Is there a Python 3 IDE that contains breakpoints and pop up hints?

2. Is it a terrible idea to use version 2 and Spyder instead of version 3 and some possibly lesser IDE?

Why not just keep using Visual Studio?

Drunk Badger
Aug 27, 2012

Trained Drinking Badger
A Faithful Companion

Grimey Drawer

I thought I tried this once, and it didn't work. I'll give it another try since it supports VS 2012.

Lurchington
Jan 2, 2003

Forums Dragoon

Drunk Badger posted:

I'm making a serious attempt at learning Python, so I'm looking for a good Python IDE. The only other IDE I have good experience with is Visual Studio for a C# and C++ class, pop up tips and the ability to set break points with a nice list of variables and their values are probably the two things that helped the most in learning those, and as a novice programmer, probably things I require to hold my hand as I get into Python.

After looking at the IDE list I see that Spyder looks like a decent choice, the only downside is that it looks like it only supports Python 2, and I'd like to stick with version 3.

So my questions are:

1. Is there a Python 3 IDE that contains breakpoints and pop up hints?

2. Is it a terrible idea to use version 2 and Spyder instead of version 3 and some possibly lesser IDE?


I strongly, STRONGLY recommend PyCharm: http://www.jetbrains.com/pycharm/

I've spent money on both a personal license and had the company shell out too. There are a few free license options, but I mention the fact I've paid for it to show that I definitely believe in it.


Rocko Bonaparte posted:

I wonder if anybody here has tried to do a REST client in Python using the requests module in particular, but I generally have a flow control question. I am doing a streaming get, which looks to be designed to run forever if you let it. However, I'd like to be able to break out of it in the most proper, elegant way possible. Right now, I just break out of the loop processing it and that's that.


This library: http://slumber.in/ (originally found it in this thread actually) has been great for rest stuff whenever I've needed it, and it uses requests under the hood. Maybe it'll help you one way or the other.

OnceIWasAnOstrich
Jul 22, 2006

Lurchington posted:

I strongly, STRONGLY recommend PyCharm: http://www.jetbrains.com/pycharm/

I've spent money on both a personal license and had the company shell out too. There are a few free license options, but I mention the fact I've paid for it to show that I definitely believe in it.


I'll second PyCharm, its worked pretty well for me mixing 2.7/3.3/Pypy.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
Count me as another STRONG vote for PyCharm. I exclusively use it to write Python 3.2 and 3.3 code, and it's never let me down.

spankweasel
Jan 4, 2006

I won a personal license for PyCharm from the last PyCon. I've only downloaded and installed it. I have yet to actually use it for anything. :negative:

Thermopyle
Jul 1, 2003

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

PyCharm is pretty amazing. I can't quite get myself to pay for it since I don't get paid to code.

I mostly use Sublime Text anymore. It's not a full IDE, but it's pretty sweet.

Modern Pragmatist
Aug 20, 2008

Thermopyle posted:

PyCharm is pretty amazing. I can't quite get myself to pay for it since I don't get paid to code.

I mostly use Sublime Text anymore. It's not a full IDE, but it's pretty sweet.

If you do any open source development, PyCharm has a free license that has to be renewed by the lead developer of the project annually.

Red Mike
Jul 11, 2011
I've got an open source licence for PyCharm for one of my projects. After applying, it took something like a week for them to review my project/application and issue my licence. It's really good. Only problem I've ever ran into with it was broken git integration in a specific version of it, which I believe has since been fixed.

BigRedDot
Mar 6, 2008

A few weeks ago my company put on PyData NYC, a conference dedicated to data analytics with python. Authors and contributors of numpy, scipy, pandas, pytables, ipython, and other projects all gave great talks to several hundred attendees. Today all the talks were made available on Vimeo, for anyone interested!

http://vimeo.com/channels/pydata/videos/sort:preset/format:detail

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

BigRedDot posted:

A few weeks ago my company put on PyData NYC, a conference dedicated to data analytics with python. Authors and contributors of numpy, scipy, pandas, pytables, ipython, and other projects all gave great talks to several hundred attendees. Today all the talks were made available on Vimeo, for anyone interested!

http://vimeo.com/channels/pydata/videos/sort:preset/format:detail
Oh, this is loving perfect for what I'm working on right now. Thanks very much!

The Gripper
Sep 14, 2004
i am winner

Thermopyle posted:

PyCharm is pretty amazing. I can't quite get myself to pay for it since I don't get paid to code.

I mostly use Sublime Text anymore. It's not a full IDE, but it's pretty sweet.
I've been using Sublime Text 2 for most things as well, lately. With CodeIntel it's a pretty good IDE for most languages. My only gripe with it is that CodeIntel doesn't show parameter hints, though maybe that's something wrong with my setup (for python you can type "functionname." and get a list of parameters that way, but it's clumsy).

If I had an IDE for every language I use weekly I'd have dozens of them, so I figure sticking with an all-in-one that works is probably the most efficient!

edit; apparently updating to the latest build or restarting fixed the parameter hints, though they're still clumsy (show up only in the status bar, and only after typing one parameter and a comma!).

The Gripper fucked around with this message at 07:45 on Nov 11, 2012

Obdicut
May 15, 2012

"What election?"
Heya

Mostly Newbie to Python. I'm tying to open up a .csv saved by openoffice and getting the Errno 22: invalid mode 'rb' or filename 'C:\\python\\test.csv' error.

Right before that, I open up another csv-- whose origins I don't know, but may be openoffice as well, or might be excel.

Here is the code:

import csv

SubsetCL = []
# this defines an empty array to be filled with the first file data (not actually necessary)
SubsetNature = []
# this defines an empty array to be filled with the second file data (not actually necessary)
tower = open("C:\python\CLA_Corynn_SubsetPython.csv", "rb")
# this opens the first file for reading only
grail = open("C:\python\test.csv", "rb")
# this opends the second file for reading only
credits = ("ComparisonResults.csv", "w")
#this creates a csv file called "ComparisonResults.csv" and sets it to be writeable

and the error is on line 9, grail = open("C:\python\test.csv", "rb")

Any thoughts?

I can't upload the file, unfortunately, since it's proprietary.

Obdicut fucked around with this message at 16:57 on Nov 11, 2012

The Gripper
Sep 14, 2004
i am winner
I don't know, there's a few things that could go wrong there.

\t is a special escape character (tab), so in your loading of test it's probably replacing it with C:\\python\test.csv (non-existant because \t is a tab character). You can either just use double \'s in the filename, or quote it as a raw string i.e. open(r"C:\python\test.cvs","rb").

Then again, if you typed the error out correctly then you may have just spelled test.csv as test.cvs.

I'm going to assume you're using Python 2.7 and the \t escaping is your problem, since Python 3.3 gives a better error (invalid argument c:\\python\test) instead of the ambiguous one 2.7 gives.

The Gripper fucked around with this message at 16:46 on Nov 11, 2012

Obdicut
May 15, 2012

"What election?"

The Gripper posted:

I don't know, there's a few things that could go wrong there.

\t is a special escape character (tab), so in your loading of test it's probably replacing it with C:\\python\test.csv (non-existant because \t is a tab character). You can either just use double \'s in the filename, or quote it as a raw string i.e. open(r"C:\python\test.cvs","rb").

Then again, if you typed the error out correctly then you may have just spelled test.csv as test.cvs.

I'm going to assume you're using Python 2.7 and the \t escaping is your problem, since Python 3.3 gives a better error (invalid argument c:\\python\test) instead of the ambiguous one 2.7 gives.

Yes, that was it. Than you very kindly. Used raw and it solved the problem immediately.

Obdicut
May 15, 2012

"What election?"
And sorry to be a pest, but can someone explain this bit of code to me?
code:
f1 = file('hosts.csv', 'r')
f2 = file('masterlist.csv', 'r')
f3 = file('results.csv', 'w')

c1 = csv.reader(f1)
c2 = csv.reader(f2)
c3 = csv.writer(f3)

masterlist = [row for row in c2]

for hosts_row in c1:
    row = 1
    found = False
    for master_row in masterlist:
        results_row = hosts_row
        if hosts_row[3] == master_row[1]:
            results_row.append('FOUND in master list (row ' + str(row) + ')')
            found = True
            break
        row = row + 1
    if not found:
        results_row.append('NOT FOUND in master list')
    c3.writerow(results_row)

What are the hosts_row, master_row, and results_row bits? I don't see master_row getting defined before it's used, for example. And if they're strings, which they kind look like they are, how can you append anything to them?

Obdicut fucked around with this message at 18:26 on Nov 11, 2012

Jewel
May 2, 2009

Obdicut posted:

And sorry to be a pest, but can someone explain this bit of code to me?

f1 = file('hosts.csv', 'r')
f2 = file('masterlist.csv', 'r')
f3 = file('results.csv', 'w')

c1 = csv.reader(f1)
c2 = csv.reader(f2)
c3 = csv.writer(f3)

masterlist = [row for row in c2]

for hosts_row in c1:
row = 1
found = False
for master_row in masterlist:
results_row = hosts_row
if hosts_row[3] == master_row[1]:
results_row.append('FOUND in master list (row ' + str(row) + ')')
found = True
break
row = row + 1
if not found:
results_row.append('NOT FOUND in master list')
c3.writerow(results_row)


What are the hosts_row, master_row, and results_row bits? I don't see master_row getting defined before it's used, for example. And if they're strings, which they kind look like they are, how can you append anything to them?

The line "for master_row in masterlist" is iterating over master list, like this:

Python code:
fruit_list = ["banana", "orange", "apple"]
for fruit in fruit_list:
    print fruit + " is good"
Which should output each fruit followed by " is good", on new lines.

Strings can't be appended to but I guess csv readers return an array containing the string or somesuch? Don't know much about that part, going to bed so too tired to search it up. Also use [code=python] tags, python relies on indentation which you don't have without them!

Edit: Yeah, quickly searched it up. "Each row read from the csv file is returned as a list of strings"

Jewel fucked around with this message at 18:19 on Nov 11, 2012

The Gripper
Sep 14, 2004
i am winner
That's just how for loops work. You ask it to iterate over each element in a list or iterable, and give it a variable name to access the current element by:
Python code:
numbers = [1,2,3,4,5]
for current in numbers:
   print current
Will print 1, 2, 3, 4, 5 (each on their own line).

That code is confusing because results_row is defined by copying hosts_row (and the paste removed all the indenting), but as far as I can tell all three _row variables are lists.

Obdicut
May 15, 2012

"What election?"

The Gripper posted:

That's just how for loops work. You ask it to iterate over each element in a list or iterable, and give it a variable name to access the current element by:
Python code:
numbers = [1,2,3,4,5]
for current in numbers:
   print current
Will print 1, 2, 3, 4, 5 (each on their own line).

That code is confusing because results_row is defined by copying hosts_row (and the paste removed all the indenting), but as far as I can tell all three _row variables are lists.


Jewel posted:


Edit: Yeah, quickly searched it up. "Each row read from the csv file is returned as a list of strings"

Thank you both very kindly for your help.

I may be being dense, but:

A) If they're lists, why can't I append?
B) Why does "for hosts_row in c1:" create a list? You don't have to declare it first?

The Gripper
Sep 14, 2004
i am winner
c1 is a csv.reader, and each row it reads from a CSV file is a list of columns in that row (e.g. a row containing "some,kind,of,data" becomes a list ["some","kind","of","data"]), so in that case each row is a list of columns in the row (so hosts_row is that list). The for loop basically breaks up a group of <things> into one <thing> at a time, no matter what that <thing> is.

You don't really need to declare anything in Python to assign to it, which is all the for loop is doing automatically for you.

It's equivalent to this:
Python code:
n = 0
while n < len(c1):
  hosts_row = c1[n]
  ... whatever logic here ...
  n+=1
except it does the assignment to hosts_row itself (because you told it to) and without needing to check the length of c1 and creating a regular while loop.


I don't know why you wouldn't be able to append, what are you trying to append to and what is happening instead of what you want?

The Gripper fucked around with this message at 19:19 on Nov 11, 2012

Obdicut
May 15, 2012

"What election?"

The Gripper posted:

c1 is a csv.reader, and each row it reads from a CSV file is a list of columns in that row (e.g. a row containing "some,kind,of,data" becomes a list ["some","kind","of","data"]), so in that case each row is a list of columns in the row (so hosts_row is that list). The for loop basically breaks up a group of <things> into one <thing> at a time, no matter what that <thing> is.

You don't really need to declare anything in Python to assign to it, which is all the for loop is doing automatically for you.

It's equivalent to this:
Python code:
n = 0
while n < len(c1):
  hosts_row = c1[n]
  ... whatever logic here ...
  n+=1
except it does the assignment to hosts_row itself (because you told it to) and without needing to check the length of c1 and creating a regular while loop.


I don't know why you wouldn't be able to append, what are you trying to append to and what is happening instead of what you want?

Gah, sorry, I solved it. I just had all my references backwards. I had this stuff:

tower = file("C:\python\CLA_Corynn_SubsetPython.csv", "r")
tim = csv.reader(tower)

and was referring to the wrong one. As soon as I fixed it, It worked fine.

Final code for the curious:

code:
tower = file("C:\python\CLA_Corynn_SubsetPython.csv", "r")
# this opens the first file for reading only
grail = file(r"C:\python\test.csv", "r")
# this opends the second file for reading only
credits = file(r"C:\python\ComparisonResults.csv", "w")
#this creates a csv file called "ComparisonResults.csv" and sets it to be writeable
tim = csv.reader(tower) 
#this runs the csvreader passing tower as the argument, 
#so it functions as opening tower using the csv interpreter in python
lancelot = csv.reader(grail)
galahad = csv.writer(credits)
masterlist = [row for row in lancelot]
for tower_row in tim:
	row = 1
	for grail_row in masterlist:
		credits_row = grail_row
		if tower_row[0] == grail_row[1]:
			credits_row.append(row)	
			break
		row = row + 1
	galahad.writerow(credits_row)
		
tower.close()
grail.close()
credits.close()

Thermopyle
Jul 1, 2003

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

What's the right way to transfer files to/from a samba share in a python script running on an Ubuntu system without storing the users auth information?

I assume there is a way of doing this because you don't have to input your Samba credentials when you double-click a Samba share in Nautilus...

geonetix
Mar 6, 2011


Nautilus does this by using the credentials stored in the gnome-keyring. That obviously does store the credentials, but needs unlocking once in a while. I found this thing in the cheeseshop. Maybe that will help you.

Adbot
ADBOT LOVES YOU

Suspicious Dish
Sep 24, 2011

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

Thermopyle posted:

What's the right way to transfer files to/from a samba share in a python script running on an Ubuntu system without storing the users auth information?

I assume there is a way of doing this because you don't have to input your Samba credentials when you double-click a Samba share in Nautilus...

You can use Gio to do the copy directly, which will use the credentials from the keyring.

Python code:
from gi.repository import Gio

source = Gio.File.new_for_path("/home/thermopyle/garbage/virus.dll")
target = Gio.File.new_for_uri("smb:///ebay/C$/Windows/system32/kernel32.dll")

source.copy(target, Gio.FileCopyFlags.NONE, None, None)

  • Locked thread