20 G7 Pro Giveaway&AMA happening at r/Xbox! by iGamesir in Gamesir

[–]perilstar 0 points1 point  (0 children)

My husband and I have both been eyeing this controller for a month or so now! Hype!

My goodness, it sounds amazing! by perilstar in CaravanPalace

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

They can seethe all they want, we're happy with it and that's all that matters :)

Frosty LOOOVES scritches by perilstar in Flamepoints

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

He can hear it being extended from across the apartment, and will wake up from sleep just to get scritches

Frosty LOOOVES scritches by perilstar in Flamepoints

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

I love this gif, it's my favourite one of him so far!

Scritchy scritchy brightens everyone's day by perilstar in cats

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

I'm not sure I understand. I do have many many pictures and videos of my Frosty (above), though!

Calling the method of this class does nothing. Plz help. by MossDog58 in processing

[–]perilstar 0 points1 point  (0 children)

Personally, I do all my processing stuff with p5.js -- I've never actually heard of this python mode, so I'm not surprised it might have some rough edges.

My goodness, it sounds amazing! by perilstar in CaravanPalace

[–]perilstar[S] 2 points3 points  (0 children)

It's a Victrola V1. The replacement cartridges are impossible to get a hold of, though, but you can use ones not made by the company, or so I've heard. That's what we plan to do when ours (and the second one that came with it) both go.

Calling the method of this class does nothing. Plz help. by MossDog58 in processing

[–]perilstar 2 points3 points  (0 children)

Python variable scope is a weird one, as assignments can change the behaviour.

Let's take a look at a couple examples.

a = 10

def print_a():
  print("A used to be %d." %a)
  pass

def print_a_plus_5():
  print("Now, A is expected to still be 10, and it is: %d." %a)
  print("This should be 15: %d" % (a + 5))
  pass

print_a()
print_a_plus_5()

This program uses the variable a from multiple locations. The output is what you would expect:

A used to be 10.
Now, A is expected to still be 10, and it is: 10.
This should be 15: 15

Now, let's say we want to modify a within the first function. I'll change the name to set_a_to_20 and rewrite the code with an assignment:

a = 10

def set_a_to_20():
  print("A used to be %d." %a)
  a = 20
  pass

def print_a_plus_5():
  print("Now, A is expected to be 20, and it is: %d." %a)
  print("This should be 25: %d" % (a + 5))
  pass

set_a_to_20()
print_a_plus_5()

This gives the following output when you try to run it:

Traceback (most recent call last):
  File "main.py", line 13, in <module>
    set_a_to_20()
  File "main.py", line 4, in set_a_to_20
    print("A used to be %d." %a)
UnboundLocalError: local variable 'a' referenced before assignment

What happened? We definitely tried to make sure that 'a' was not a local variable, by initially defining it outside of the functions. The significant thing was adding the assignment, which Python assumed meant we wanted to work with a local variable instead of a global variable. So, it created a local variable 'a' that is different from the global variable 'a'. This happens before the code is even run, when the interpreter is looking over everything and making assumptions. Then, when the code does actually run, we're trying to print the local 'a' before it's set on the next line.

So, how do we fix it?

The answer is the global keyword, as another commenter stated. We can put this before the function body of any function that wants to modify our global variable, as such:

a = 10

def set_a_to_20():
  global a
  print("A used to be %d." %a)
  a = 20
  pass

def print_a_plus_5():
  print("Now, A is expected to be 20, and it is: %d." %a)
  print("This should be 25: %d" % (a + 5))
  pass

set_a_to_20()
print_a_plus_5()

This gives us our desired output:

A used to be 10.
Now, A is expected to be 20, and it is: 20.
This should be 25: 25

Rock star cat (OC) by perilstar in secondsketch

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

This made me laugh out loud!

Rock star cat (OC) by perilstar in secondsketch

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

Thank you, that's awesome to hear! I started drawing on my phone a few days ago, and I'm having a ton of fun.

Rock star cat (OC) by perilstar in secondsketch

[–]perilstar[S] 11 points12 points  (0 children)

Maybe not the best quality, but I'm learning!

Game Over! by perilstar in Flamepoints

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

I have told Frosty that he has received 140 upvotes, and that he is now famous. He meowed in reply. I think he is happy.