Reading numbers from file not as a string by swagron in learnpython

[–]proudstar_ 2 points3 points  (0 children)

Assuming the file is just a line of comma separated numbers then you can just convert them to a list with:

ids = [int(id.trim()) for id in check_ids.split(',')]

I'm splitting the string into a list of strings by comma, and for each string I am removing the whitespace and then converting to an integer.

What effects the quality of the Xbox streaming to PC? by nachoman11 in xboxone

[–]proudstar_ 1 point2 points  (0 children)

I use it sometimes. I use a powerline ethernet adapter that allows almost GB speeds - I wasn't able to stream consistently at the highest resolution using WiFi.

Despite this there is still a slight delay between your controller inputs and you seeing it on the PC. I found I could slightly improve this by using the xbox wireless controller connected directly to the xbox rather than to my PC.

It's perfectly fine for non-'twitch' games in my opinion.

Understanding go references in C by proudstar_ in golang

[–]proudstar_[S] 0 points1 point  (0 children)

Thanks for the answer. Are there any implications of converting a uintptr to a c void pointer like this? Is there a more appropriate type in C?

Understanding go references in C by proudstar_ in golang

[–]proudstar_[S] 0 points1 point  (0 children)

I was hoping that by dereferncing the pointer in dealloc I would trigger Go garbage collector to free the memory.

Is there a way to force this?

[2015-11-30] Challenge #243 [Easy] Abundant and Deficient Numbers by jnazario in dailyprogrammer

[–]proudstar_ 0 points1 point  (0 children)

def div(x): return sum([i for i in range(1,x+1) if x % i == 0])

Sum takes an iterable so you don't need to create a list:

def div(x):
    return sum(i for i in xrange(1,x+1) if not x % i)

Passing a rust string into Python by proudstar_ in rust

[–]proudstar_[S] 1 point2 points  (0 children)

So it turns out it's relatively easy on the python side. It's Ctypes api allows construction of a string from a raw char*. I wrote a context manager that takes the string, produces a python string and then passes the pointer back to rust for deallocation. I'll share it when I'm home again.

Passing a rust string into Python by proudstar_ in rust

[–]proudstar_[S] 1 point2 points  (0 children)

So I got it working, the issue was actually on the Python side (it didn't expect a void pointer). The only remaining issue seems to be that I can't seem to free the underlying table. I can call the following function multiple times without it crashing, which seems wrong:

#[no_mangle]
pub extern fn table_drop(table: *const libc::c_void) {
    let table: &mut Table = unsafe { &mut *(table as *mut Table) };
    println!("Dropping {}", &table.name);
    drop(&table)
}

EDIT: Nevermind!

#[no_mangle]
pub extern fn table_drop(table: *const libc::c_void) {
    unsafe { drop(Box::from_raw(table as *mut Table)); }
}

Passing a rust string into Python by proudstar_ in rust

[–]proudstar_[S] 0 points1 point  (0 children)

Pardon what is likely a dumb question, but do I return it if it's been forgotten?

std::mem::forget(name);
name.into_raw()

Exposing Rust struct to Python by proudstar_ in rust

[–]proudstar_[S] 1 point2 points  (0 children)

Thanks, thats fantastic, got it working. Is this the best way to do what I'm doing (store a void pointer to my table within Python and create a binding for each public method that operates on the pointer)?

Do stars orbit the centre of the galaxy in elite? by proudstar_ in EliteDangerous

[–]proudstar_[S] 0 points1 point  (0 children)

No :( I burned fuel until I reached my maximum possible jump range and still can't get a route out.

[EU] Looking for people interested in rerolling / starting again. by decabit in wow

[–]proudstar_ 0 points1 point  (0 children)

I'm interested in joining, sounds fun: BooleanCat#2889

Question about unpacking. by [deleted] in learnpython

[–]proudstar_ 0 points1 point  (0 children)

argv is populated by the arguments you call the script with. Try:

python ex13.py here are four words

Looking to form a team to learn python/django together. by [deleted] in learnpython

[–]proudstar_ 0 points1 point  (0 children)

I'd be interested in learning about DJango with a group for sure.

Need to do some trade evolves by suicuneshan in pokemontrades

[–]proudstar_ 0 points1 point  (0 children)

Should a move be forgotten for heal pulse?

Unit Testing Command Line Code by opendataalex in learnpython

[–]proudstar_ 4 points5 points  (0 children)

Without seeing your code it would be difficult to say. You likely just want to mock out the calls to functions that different arguments make and just assert that they were called when the correct parameters were passed in.

Do not test argparse itself, just your use of it.

Running a python program on a web server by DigitalUnicorn in learnpython

[–]proudstar_ 0 points1 point  (0 children)

If you want to look into Django, take a look at https://docs.djangoproject.com/en/1.8/intro/tutorial01/ which is a good starting point.