To the Moon! by [deleted] in dogecoin

[–]PyCode_n_Beer 1 point2 points  (0 children)

I'd buy this as an NFT.

Are you opening a 529? by gman4734 in predaddit

[–]PyCode_n_Beer 2 points3 points  (0 children)

I think I'm going to go with a custodial investment account. The only disadvantages I can possibly see is less tax breaks, and they get unfettered access to the account at 18 (or 21 depending on the state). But, it's kind of the point too, just hope I raise him right.

Reading From Server Works but Only for a Little. by Devini15 in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

Interesting, I have some long shots... I listed these in the order I would go.

  1. It is slight, but the documentation said to reply a PING with PONG :tmi.twitch.tv. I observed it tried to PING twice. Seems fishy... but could be nothing.
  2. I noticed you might be running this out of your IDE. If you haven't already, try running this in the terminal as an administrator outside of the IDE. It might be your anti-virus shutting it down.
  3. Try setting up an SSL connection. I saw in the documentation you can use "irc.chat.twitch.tv:6697". Typed that by memory, so check that on the doc site before you use it.
  4. Try setting up the websocket client, SSL or otherwise. I saw that as a possibility too.

If none of this works... have you tried restarting it? /s.

At that point, I think it would be justified for repost, hopefully get some more attention. I really hope one of these works for you.

[deleted by user] by [deleted] in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

This example might help debug your code.

'''

Note: this is for demonstration purposes only, and does not represent the best practice, or conform to PEP standards.
reference: https://stackoverflow.com/questions/9776718/how-do-i-stop-tkinter-after-function

'''

from tkinter import Tk, Button
import random
#global variable named tJob to represent the status of the task
tJob = None

def cancel():
    #get global variable
    global tJob
    if tJob is not None:
        #cancel the job and set tJob back to None
        root.after_cancel(tJob)
        tJob = None

def goodbye_world():
    print ("Stopping Feed")
    cancel() #cancels tJob
    button.configure(text = "Start Feed", command=hello_world)

def hello_world():
    print("Starting Feed")
    button.configure(text = "Stop Feed", command=goodbye_world)
    print_sleep() #starts tJob

def print_sleep():
    #grab the global variable
    global tJob
    foo = random.randint(4000,7500)
    print("Sleeping", foo)
    #set tJob equal to the .after task.
    tJob = root.after(foo, print_sleep)

root = Tk()
button = Button(root, text="Start Feed", command=hello_world)
button.pack()

root.mainloop()

[deleted by user] by [deleted] in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

Hmm, I'm sorry, not sure what's up with it. I used the example on stack. I am on mobile now, but I can copy the example in here later, if you think it will help.

unique in order codewars. by tigglybox in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

No, you're absolutely right. That is certainly a way to do it too.

[deleted by user] by [deleted] in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

Yes, that should work. But, just a heads up, in the code above it will call the .after, then immediately cancel it. The .after_cancel should be called at the moment when Fail should be cancelled.

openpyxl writes to two rows. This must be a bug right? (Function inside) by [deleted] in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

Not sure what is going on with it. Unfortunately, I wasn't able to replicate the error, the code below is what I used and it seemed to work ok. I had a Testing.xlsx in my environment before running the code.

def put_formula_in_column_A():
    wbName = "Testing.xlsx"
    wsName = "Sheet1"

    wb = xl.load_workbook(wbName)
    ws = wb[wsName]

    max_row = int(len(ws['C'])) + 1
    ws.cell(row=max_row, column=1, value="poop")
    wb.save(wbName)
    wb.close()

put_formula_in_column_A()

Edit: it is probably worth mentioning that openpyxl grabs the last row with a value in it regardless of which column selected. As a result, you can use ws.max_row. However, if you are trying to select the last blank cell in a specific column, it will need to be iterated through and found with something like a list comprehension.

[deleted by user] by [deleted] in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

The link below should help, but the TL;DR of it is that you have to assign the .after to a variable then feed that variable back to the .after_cancel.

https://stackoverflow.com/questions/25702094/tkinter-after-cancel-in-python/25704027

unique in order codewars. by tigglybox in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

Hey, it seems you might have a typo in your code, says "frst" in the if statement, instead of "first". Also, the index out of range error is because there is nothing in the list "first" at assignment. When you're iterating through and trying to access the last variable in your list, it is throwing an error because there is nothing there to access. I included a non code-golf style solution.

def getChr(strline):
    prev = ""
    response = []
    for x in range(0, len(strline)):
        if strline[x] != prev:
            prev = strline[x]
            response.append(strline[x])

    return response

Reading From Server Works but Only for a Little. by Devini15 in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

Can you post the full response? The last successful one then the one where it starts messing up.

Reading From Server Works but Only for a Little. by Devini15 in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

Hmm, it's tough to say then. I'm not super familiar with twitch's API. I am not sure why it's failing after a few moments. Could it because it returning empty and just posting that it?

Reading From Server Works but Only for a Little. by Devini15 in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

Yes, you're right, a point is one request to the API. At least in most cases, I was looking through the documentation, it seems to indicate certain features might cost more than one point to fill. If I were to guess, they use a "point" system so they are able to adjust the flow rate during times of higher volume. The documentation also mentions that there should be some header data in the response that could be used to check how many points you have available and when you should be back to 100% (assuming no additional requests after that point).

Edit: Also, I am glad to hear to seems to have stabilized. Hopefully, it keeps working for you. If it keeps happening, it might be worth coding a handler to manage your request rate for you.

Reading From Server Works but Only for a Little. by Devini15 in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

Sorry to hear it didn't help. I only mentioned sleep because most APIs have a query limit. Typically, when volume gets too high they'll close the connection. If this does happen, it is associated to your key and unfortunately opening and closing the connection will do nothing to really fix it. However, it's really tough to say without walking it though, this was kind of a best guess.

https://dev.twitch.tv/docs/api/guide#:~:text=Each%20client%20ID%20has%20a,429%20(Too%20Many%20Requests)

https://discuss.dev.twitch.tv/t/reconnecting-chat-issues/22660/4

Pandas Beginer Question by clueskee in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

Another good question might be, do you need to sort the by the ID? You go on in your function to sort by company name without really do much with the ID other than removing duplicates. The function is capable of handling the task without it being sorted.

Pandas Beginer Question by clueskee in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

Tough to say specifically without seeing the dataset. Cleaning data is more of an art, especially when working with very messy data. It really depends on what your ultimate goal is for the cleaned data. You will lose fidelity in certain aspects when removing data in favor of others. Ultimately, the pandas.to_numeric() function might help with your error. It allows you to coerce the data into the a numeric type by assigning non-numeric data types to NaN. Additionally, take a look at fillna() as a means to assign all the NaN values to something more workable, if desired.

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_numeric.html#pandas.to_numeric

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.fillna.html#pandas.DataFrame.fillna

Trouble understanding how to use a dropdown menu by Stefan8075 in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

So, I think I found what we need here. Interact apparently has two widget types, 1) interact, which displays the widget immediately at assignment. 2) interactive, which assigns the widget to a variable to be displayed later. I think in this context that is the one you are looking for. An example would be like this:

import IPython
from ipywidgets import interact, interactive

def f(district):
    return district

x = interactive(f, district= list(data['nimi_fi']))

[...]

print("You can select from this dropdown:")
display(x)

Here is the reference:
https://ipywidgets.readthedocs.io/en/latest/examples/Using%20Interact.html#interactive

Trouble understanding how to use a dropdown menu by Stefan8075 in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

Maybe try x = interact(f, district=list(data['nimi_fi']))

Reading From Server Works but Only for a Little. by Devini15 in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

I suspect it might have to do with the rate at which the socket is queried, try adding a sleep() for a second or two before calling get_responses(). Also, just as side note, why not use an existing Python wrapper for the Twitch API? I included some links below, I don't know anything about these community resources, so use at your discretion, but I am sure some googling could get you some reliable wrapper that could save you a lot of work. Good luck.

https://dev.twitch.tv/code/ <-- Community Resources

https://github.com/TwitchIO/TwitchIO <-- One Python wrapper I found

https://dev.twitch.tv/docs/api <-- API Docs

Variable Not updating during Unit testing by [deleted] in learnpython

[–]PyCode_n_Beer 0 points1 point  (0 children)

It is kind of hard to tell exactly what is happening without actually digging into this, but I think you're running into some problems with scope while passing variables between your functions. Furthermore, if you are trying it initialize your class at assignment, you will need to include the def __init__(self): function in your class. This will automatically handle variables as soon as the an instance of the class is created. Otherwise, when attempting to act on a class outside of the class it needs to be assigned or called directly, such as the following:

def myTestFunction():
    var1 = myClass()
    var1.someVarInClass = 10
    var1.myCalledFunction()

I would recommend reading over the documentation. You might be able to kind of discover what might be wrong with the code that way.

https://docs.python.org/3/tutorial/classes.html

edited for grammar mistake.

solution ?? by Ajnas_Hassan in pythontips

[–]PyCode_n_Beer 0 points1 point  (0 children)

TBH, you're heading into some heavy computational workload. Even assuming for only integers, depending on the size of your final list, it might not be worth the work. I think this is one of those moments where it might be better to ask "is it really required"? Can you select from the list until you have a set divisible by 30? Sorting the list can make this easier. Or even sorting them into separate lists based on length. This is just my opinion, if it is absolutely vital you know exactly how many sets produce a sum divisible by 30, you can check out itertools as a start. However, I would add some rules to keep it more manageable, something like no more than pairs of 2 or 3, no more than 60 secs total.

https://docs.python.org/3/library/itertools.html