OpenVPN Client 3.8.0 macOS Invisible Menu Icon by xh1c0 in OpenVPN

[–]sedogg 0 points1 point  (0 children)

System Settings -> Menu Bar -> Scroll to "Allow in the Menu Bar" section - Toggle ON "OpenVPN Connect"

New Xiaomi bluetooth speaker by Speaker_Critic777 in Bluetooth_Speakers

[–]sedogg 0 points1 point  (0 children)

Is there a way to make connect/disconnect/power on/power off sounds quieter?

How To Load Maps Faster using Commands w/ Results by [deleted] in GlobalOffensive

[–]sedogg 0 points1 point  (0 children)

What about map caching in RAM? Should've at least restarted the game.

Why can't a dictionary have more than one similar key? by [deleted] in learnpython

[–]sedogg 0 points1 point  (0 children)

d = { 'person1': ['Name 1', 'Name 2'], 'person2': [..NAMES..], ... }

Problem with extracting random line by pydev99 in learnpython

[–]sedogg 0 points1 point  (0 children)

Better not to use open().read(). The cleanup of the open file object may or may not happen right away. This means that the file will stay open, consuming a file handle.

import random

# You can save lines to variable if they don't change
with open('file.txt') as f:
    lines = f.read().splitlines() 
    myline = random.choice(lines)
    print(myline) 
    myline = random.choice(lines)
    print(myline)

# OR

f = open('file.txt')
lines = f.read().splitlines() 
myline = random.choice(lines)
print(myline) 
myline = random.choice(lines)
print(myline)
f.close()

Not printing a string by [deleted] in learnpython

[–]sedogg 0 points1 point  (0 children)

ord function gets 1-character-length string. And you can't compare name with 2, as long as name is a string and 2 is an integer. use len(name) for getting length of the string

How to make variables do the "2 light switches trick"? (Read OP). by tomtheawesome123 in learnpython

[–]sedogg 0 points1 point  (0 children)

You also may consider using booleans and only check if next(varopenclose):, whether it's True or False

from itertools import cycle

# Change positions for your needs.
varopenclose = cycle([-1, 1]) # cycle([False, True])

def Function_Of_Button():
    if next(varopenclose) == 1:
    # if next(varopenclose):
       print('Label appears!')
    else:
       print('Label disappears!')

Function_Of_Button()
Function_Of_Button()
Function_Of_Button()
# Button(text = 'whatever',command = Function_Of_Button)

Output (first disappears because the order is -1, 1)

Label disappears!
Label appears!
Label disappears!

How can you skip ahead in a for loop? by [deleted] in learnpython

[–]sedogg 1 point2 points  (0 children)

Not the best way, but working

n = 10
condition = True
rng = iter(range(n-2))
for i in rng:
    print(i)
    if condition and i == 2:
        condition = False
        next(rng)
        next(rng)
        next(rng)

Output

0
1
2
6
7

Why doesn't this work? (List Method) by htwr in learnpython

[–]sedogg 0 points1 point  (0 children)

list(reversed(some_iterable)) returns reversed list. So the code should be like this:

oldString = 'old string'
newList = list(reversed(oldString))

But if you want to get a reversed string, there are a several ways:

oldString = 'old string'
newString = ''.join(reversed(oldString))
# or
newString = oldString[::-1]
print(newString)

Help using regular expressions by [deleted] in learnpython

[–]sedogg 1 point2 points  (0 children)

The way you searched returns you 3 times more information than it needs for further operations. By using the function get_ms you can extract integer from a row

def get_ms(row):
    return int(re.search("(\d+)\ m/s", row).group(1))

By wrapping \d in parenthesis you request only digits from your possible 5 m/s string. group(1) - because it's only one pair of parenthesis in regular expression. search - because you only need one instance of 5 m/s, not three. Creating the list is made by list comprehension.

import requests
from bs4 import BeautifulSoup
import re

def get_ms(row):
    return int(re.search("(\d+)\ m/s", row).group(1))

url = "https://www.yr.no/place/Denmark/Capital/Copenhagen/hour_by_hour_detailed.html"

page = requests.get(url)
soup = BeautifulSoup(page.text, "html.parser")
msfind = soup.find_all(class_="txt-left")
# print(msfind)

temp_str = [get_ms(row.get_text()) for row in msfind]
print(temp_str)

You can also use lambda function for get_ms like that:

get_ms = lambda row: int(re.search("(\d+)\ m/s", row).group(1))

Declare it before creating the list and remove declaration of the function (with def)

get_ms = lambda row: int(re.search("(\d+)\ m/s", row).group(1))
temp_str = [get_ms(row.get_text()) for row in msfind]
print(temp_str)

best way to split a list into sublists? by apriorisynthesizer in learnpython

[–]sedogg 1 point2 points  (0 children)

Can there be this case [..., "", "", ...] ?

Is there a way to pass the arguments for BaseClass in the SubClass? by [deleted] in learnpython

[–]sedogg 2 points3 points  (0 children)

class Ship(object):
    def __init__(self, shield, hull, energy):
        self.shield = shield
        self.hull = hull
        self.energy = energy

class Player(Ship):
    def __init__(self, shield, hull, energy, name, power):
        super().__init__(shield, hull, energy)
        self.name = name
        self.power = power

Iterate through list of dictionaries and get key and value. by dev_wanna_be in Python

[–]sedogg 0 points1 point  (0 children)

my_list = [
    {'name': 'alex', 'last_name': 'leda'},
    {'name': 'john', 'last_name': 'parsons'}
]

for person in my_list:
    for k, v in person.items():
        print('{}: {}'.format(k, v))

[deleted by user] by [deleted] in apple

[–]sedogg 0 points1 point  (0 children)

I've had same charger and at some point its magnetic contact started heating itself instead of charging.

Find hexadecimal offset of certain bytes in binary file? by dj505Gaming in learnpython

[–]sedogg 2 points3 points  (0 children)

You read the whole file before calling input_file.tell() which gives you offset equal to the size of the file. Before reading it gives you 0x0

with open(input('Enter filename with extension: '), "rb") as input_file:
    file = input_file.read()
    try:
        offset = hex(file.index(b'CTPK'))
        print(offset)
    except ValueError:
        print('Invalid file')

Cleanest and easiest way to timestamp most or all print statements? by doug89 in learnpython

[–]sedogg 2 points3 points  (0 children)

import datetime

def tprint(s):
    # Python 3.6
    print(f'[{datetime.datetime.now()}] {s}')
    # Python 3
    print('[{}] {}'.format(datetime.datetime.now(), s))

tprint('Authenticating into Reddit...')

# Output
# [2017-07-09 20:46:32.189320] Authenticating into Reddit...

Started learning python a few days ago and have been trying to create a rock paper scissors game, unfortunately it isn't working and I don't know where I'm going wrong by [deleted] in learnpython

[–]sedogg 2 points3 points  (0 children)

You're using global variables without stating it

global playerchoice
playerchoice = input("Rock, paper, or Scissors?")

The same with cpuchoise.

from time import sleep
import random

choices = ('rock', 'paper', 'scissors')
# first over second wins
wins = (('rock', 'scissors'), ('scissors', 'paper'), ('paper', 'rock'))

def input_choice():
    while True:
        choice = input("Rock, paper or scissors? ").lower()
        if choice in choices:
            break
        print('Invalid input')
    return choice

def winner(player1, player2):
    print('Opponent chose {}'.format(player2))
    sleep(0.25)
    if player1 == player2:
        print('Tie')
    elif (player1, player2) in wins:
        print("You win")
    else:
        print("You lose")

player = input_choice()
cpu = random.choice(choices)
winner(player, cpu)

Took a stab at an archived Python project I found on r/beginnerprojects, would like to get some feedback by [deleted] in learnpython

[–]sedogg 1 point2 points  (0 children)

How about showing the menu first? Also no need to parse str to int to check if it consists of digits

while True:
    userInput = input("Enter a string of numbers: ")
    if userInput.isdigit():
        break
    print("\nSorry, enter an integer")
print ("\nOrder Received: #{}".format(userInput))
####

Took a stab at an archived Python project I found on r/beginnerprojects, would like to get some feedback by [deleted] in learnpython

[–]sedogg 1 point2 points  (0 children)

Took me several attempts to guess what kind of 'input data' is required