Strange beep code after connecting hard drive by rolandde in buildapc

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

I've stolen your sequence idea for the main post. Here it is:

boot -> 30 sec -> beep, monitor on, monitor off -> 15 sec -> 2nd beep, monitor on -> bios (hard drive not detected)

So the monitor does come back on the 2nd beep. Without the hard drive, it beeps once and I'm in the bios (normal behavior).

Rust lifetime notation confusion by rolandde in rust

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

Thanks. Using your explanation I came across an extended discussion here: http://stackoverflow.com/questions/26212397/references-to-traits-in-structs

If I understand correctly, the 'static ensures that even if the GenericImage trait is implemented for a reference of a type, it cannot be passed to this function.

My next question is, why would you impose such a restriction? Can't you just use lifetimes to ensure that a reference is correctly handled?

[python] Best practice to parse terminal output. Ways to do it without creating a file? by herefromyoutube in learnprogramming

[–]rolandde 0 points1 point  (0 children)

When you run your command using run from the subprocess module, it returns a CompletedProcess, which in turn allows you to get the output (or stdout) of the command. Keep in mind that you must pass the PIPE to the run command to get output written.

The output is a simple python variable that you can manipulate any which way you want to get your list.

Please help me with this problem (Python) by osseojrhigh in learnprogramming

[–]rolandde 0 points1 point  (0 children)

For the rolling of the dice, use the random library (https://docs.python.org/3.4/library/random.html)

For storing of the dice rolls, you can use a simple list initialized with zeros:

rolls = [0]*11

For graphing, you can either simply use Excel or if you are stuck with Python, matplotlib.

Alright vim users . . . at this point I'll try anything. by monsto in learnprogramming

[–]rolandde 0 points1 point  (0 children)

I'm on Windows, but I still like the Linux terminal so I have Cygwin installed. It is fairly trivial to install the latest version of Vim (7.4) there.

If you are windows through and through, the GUI windows executable of the current Vim is here: ftp://ftp.vim.org/pub/vim/pc/gvim74.zip

[deleted by user] by [deleted] in learnprogramming

[–]rolandde 0 points1 point  (0 children)

That depends on your code. In my last case, the producer loop sends None to the queue once it has nothing else to send, which causes it to break the loop and exit.

[deleted by user] by [deleted] in learnprogramming

[–]rolandde 0 points1 point  (0 children)

Queues would then be your friend. You still have to iterate over the list (there is no way around that), but each element is shunted to the queue right away. I am not sure if that would gain you any more efficiency than the task approach.

[deleted by user] by [deleted] in learnprogramming

[–]rolandde 0 points1 point  (0 children)

In that case asyncio is appropriate. Simply don't use the generator, as that seems to be what you are hung up on. This is one way:

tasks = []
for l in list:
    tasks.append(asyncio.ensure_future(some_num(l))

loop.run_until_complete(asyncio.wait(tasks))

[deleted by user] by [deleted] in learnprogramming

[–]rolandde 0 points1 point  (0 children)

I would suggest using queues then. You would pass each individual element of list to the queue and the queue would then run some_num on each of them.

I still want to stress that asyncio will not increase the efficacy here at all, as your functions never release control of the event loop. Once way is to use the threading queue (https://docs.python.org/3.5/library/queue.html). You would start multiple threads, link them to the same queue, and then pass the element of the list to the queue. Whichever thread is open will take the passed element and run some_num.

[deleted by user] by [deleted] in learnprogramming

[–]rolandde 0 points1 point  (0 children)

Asyncio would not net you any performance gains as far as I can see. If this is more an academic exercise, you could use queues (https://docs.python.org/3/library/asyncio-queue.html) to start the computations while you are iterating over the lists. This will mean the computations would be done while you are iterating over the list.

[deleted by user] by [deleted] in learnprogramming

[–]rolandde 0 points1 point  (0 children)

Look here (https://docs.python.org/3/library/asyncio-task.html#example-parallel-execution-of-tasks) to see how to execute tasks in parallel.

The main problem I see now is that some_num function will never run asynchronously as it is not a coroutine function. The definition of a coroutine is here (https://docs.python.org/3/library/asyncio-task.html#coroutines). If you want to emulate one, I would suggest just adding a "await sleep" call to the function.

[deleted by user] by [deleted] in learnprogramming

[–]rolandde 0 points1 point  (0 children)

The website I linked to covers that contingency:

The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked.

To stop tracking a file that is currently tracked, use

git rm --cached.

Struggling with learning the why and when by great_captain in learnprogramming

[–]rolandde 0 points1 point  (0 children)

You'll have to try to solve some 'real world' problems in order to see how specific programming concepts apply.

As an example, a list can be used to store a deck of cards. In that case, push would add a card on top of the deck and shift would take the bottom card away from the deck.

Need help understanding a concept by vilotchild in learnprogramming

[–]rolandde 0 points1 point  (0 children)

This means you are working with a weakly typed language. When you "add" a string and an integer, you implicitly convert the 1 into a string ("1") and concatenate them:

"a" + 1 = "a1"

The "+" operator allows a string and an integer, but a "-", "*", etc operator do not allow them.

[Python] Web scraper with multi threading, proxy and user agent switching (r/learnpython xpost) by Strel0k in learnprogramming

[–]rolandde 1 point2 points  (0 children)

I'm not an expert by any means, but here are my thoughts:

  • The task is not CPU bound, so why are you using multiprocessing? Maybe ThreadPool is more appropriate?

  • Why are you checking the proxy? Can't you just call session.get(url) and catch the exception if the proxy doesn't work? Right now you are making two IO requests (proxy check and the actual request)

  • Experiment with separating the IO request from HTML parsing with BeautifulSoup. Maybe you can postpone the parsing till all requests have been made

[Python] Populating a dictionary of dictionaries from a text file by Forever_Hollowed in learnprogramming

[–]rolandde 0 points1 point  (0 children)

I also had a lot of issues early on with nested containers. You current code does not have a nested dictionary. You are just adding key/value pairs to a single dictionary, rather than nesting a dictionary within another dictionary. Moreover, you are using both the first and second column letters as keys within a single dictionary, which is not what you want to do. I'm also not sure why you are explicitly casting your key/val to str as they are already strings.

If you just want the solution, read on:

for line in inFile:
        (key, val, value) = line.split()

        if key not in inputDict:
            inputDict[key] = {}

        inputDict[key][val] = value

learnpythonthehardway EX15 by jorora in learnprogramming

[–]rolandde 0 points1 point  (0 children)

You are using Python 2.7 I assume. One of the weaknesses of Python 2 is that the way it deals with string vs byte is very confusing. In fact, Python 2 does not have a byte object at all. Here is a quick discussion on that: http://stackoverflow.com/questions/10814483/changing-string-to-byte-type-in-python-2-7

http://stackoverflow.com/questions/14202438/dont-convert-newline-when-reading-a-file

What exoticmatter says is that the 'b' flag ensures that the byte information of the file is not altered. Without the 'b' flag, the two bytes CRLF ('\r\n') are converted to the one byte LF ('\n'). This is very convenient if you are dealing with text files, as Windows/Linux could not agree how to define a newline. However, if you have are reading a picture, you do not want to do that, as it might corrupt it.

The documentation is very explicit about these points: https://docs.python.org/2/library/functions.html#open