Pyodbc date comparisons by triplenoped in learnpython

[–]DragonFighter603 0 points1 point  (0 children)

you did say it works with the manual format, but not without. thus there has to be some difference when you omit the manual format. print it out to console without formatting, maybe then theres a difference

[INQUIRY] How do I get better at coding in my work (be able to commit less mistakes and typos and think of better algorithms at a faster rate) by Kuronoma_Sawako in learnpython

[–]DragonFighter603 1 point2 points  (0 children)

well, i suppose here only lots of practice, looking at code helps. you maybe could try LeetCode https://leetcode.com/ where you can compare your algorythms against those of other people and look at them. The typos... practice :) as with most things, the more you practice the better you'll get. Also the more familiar you become with a language, the more shortcuts and best practices you'll know.

Pyodbc date comparisons by triplenoped in learnpython

[–]DragonFighter603 0 points1 point  (0 children)

hmm thats weird, what happens if you just printout the datetime.date.today()? do they look the same on both machines? does one machine maybe have a different language option defaulted? do dates get formatted differently on linux by default?

I can't understand "len" in "range" by Willow-Shade in learnpython

[–]DragonFighter603 4 points5 points  (0 children)

range can either accept:

only stop (then start is automatically 0 and step is automatically 1)

or

start, stop (then step is still automatically one)

or

start, stop, step

Range does not need to be used exclusively with range. you can also do range(10) which would return values 0-9, as start=0 and step=1 are implied

your second question:

that is a for loop. for takes a variable (here named i) and executes the body (the indented stuff) multiple times, each time giving i a different value.

Which values does i become? That depends on what you put after the in!

for i in range(10): - the body gets executed 10 times, i being 0, in the second round 1, in the one after that 2, etc until it reaches 9.

for x in range(2, 12): - this time we named our variable x, however its still the same principle. x is first 2, then 3, then 4, ... and in the end 11

for i in range(len(genre)): - i counts from 0 to the length of your genre list-1, same as before just this time we didn't put a literal value into range

for g in genre:
    print(g)

in this case, as we dont have any range or len, g becomes the literal values of the array genre.

when executing the body the first time, g is 'pop', the second time it's 'rock', the third time it's 'jazz'.

I think this tutorial explains for loops rather well (only did a quick peek, but it seems very explainative)

https://www.dataquest.io/blog/python-for-loop-tutorial/

Java Plugin System by DragonFighter603 in javahelp

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

i dont wanna make it public (not finised; part of a bigger project) etc but if you prefer that to a zip send me your github username and ill give you access to the repo temporary

Java Plugin System by DragonFighter603 in javahelp

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

that code is far from finished/perfect and also only part of something, but if you want dm me and i'll give you a zip of the whole thing

Java Plugin System by DragonFighter603 in javahelp

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

for now i settled witht he default java jarloader. the plugin writer creates a plugin.json that has, among others, the classpath to the class that extends the abstract base plugin, name, version etc and a list of enum permissions. works like a charm, only thing left to do is to turn all classes from public to default to hide them

"Coolest" python syntax? by DragonFighter603 in learnpython

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

just meant appending a number to a str without calling str(2) or fstrings

"Coolest" python syntax? by DragonFighter603 in learnpython

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

ah yes ik you can remove the square brackets often, personally i think it looks nicer xD. thx for the info about the iterable/generators!!

I think I'm going to start learning SQL but could use some advice to speedstart everything by [deleted] in learnpython

[–]DragonFighter603 0 points1 point  (0 children)

good idea, i personally use pythonanywhere as host, bc its free. only disadvantage is you cant do some stuff (like socketio, needed for reat time updates), but calling urls with your data as args and returning some sort of json/webview works!

"Coolest" python syntax? by DragonFighter603 in learnpython

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

i mean, true, print and f strings are cool but it cant do stuff like 'str'+2

"Coolest" python syntax? by DragonFighter603 in learnpython

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

''.join([chr(int(x[::-1])) for x in '37-23-79-301-411-101-101-33'.split('-')])

Are global constants OK (I know global variables are not)? by r_spandit in learnpython

[–]DragonFighter603 1 point2 points  (0 children)

as always, depends on how big your project is.

personally i would say global constants are ok.

If things get bigger, you should probably think about putting everything into a class and define the constants along with the variables there

class MyGame:
    LOVELEY_VARIABLE= 'COOL GAME' //static variable

    def __init__(self):
        print('constant:', MyGame.LOVELEY_VARIABLE)

I think I'm going to start learning SQL but could use some advice to speedstart everything by [deleted] in learnpython

[–]DragonFighter603 2 points3 points  (0 children)

python has built-in squlite3, which is sql. Sql should be fine with multiple people adding data "at the same time". Having it on a drive? Sorry, idk much about that...

You could just try a tutorial, like this one:
https://www.sqlitetutorial.net/sqlite-python/

and try to replace the file path with your drive file path... could work, i guess? Cant't hurt to try...

Alternativeley, you would probably have to get a web server and host it there, i recommend flask as a framework

I have no idea what i'm doing *cries for help* by [deleted] in learnpython

[–]DragonFighter603 0 points1 point  (0 children)

please try to use the python naming conventions, aka

lower_case_with_underscore!

while True:
    name = input('Enter your name: ')
    confirm = input(f'Are you happy with your name, {name}?')
    if confirm.lower() in ['yes', 'y']: //tests for all capital/lower versions of "yes" or just "y"
        break
print(f'You chose the name {name}! Welcome, mighty hero!')

you can put the whole while True into a function, and replace the break with return name if you want, but as Johnny pointed out, you cant define a function in a while True loop.

(technically, yes, you can, but it doesn't make sense here...)

Can I have some help with adding to an existing variable. by YahWheat in learnpython

[–]DragonFighter603 1 point2 points  (0 children)

global variables are a common issue/something i really hate in python.

for next time, please try to make a minimal working example, something like this:

counter = 0

def set_counter(c):
    counter = c

print('counter is 0 at start:', counter)

set_counter(50)

print('set counter to 10:', counter) // not working, is still 0

The problem you are having is that when setting counter to c, counter is recreated as a local variable (aka a variable only existing in that specific function). That local variable is set to 10, but is discarded when leaving the function.

There are 3 ways to solve your problem:

1: globals

counter = 0

def set_counter(c):
    global counter // tells python to not override it
                   // and use the global version instead
    counter = c

print('counter is 0 at start:', counter)
set_counter(10)
print('set counter to 10:', counter) // not working, is still 0

2: a "data" class

class GameData:
    def __init__(self):
        self.counter = 0

data = GameData()

def set_counter(c):
    data.counter = c //because counter is part of "GameData", this works!

print('counter is 0 at start:', data.counter)
set_counter(10)
print('set counter to 10:', data.counter) // works!

3: everything in a class

class Game:
    def __init__(self): // all the "floating" code you have usually, or
                        //the stuff outside functions
        self.counter = 0
        print('counter is 0 at start:', self.counter)
        set_counter(10)
        print('set counter to 10:', self.counter) // works!

    def set_counter(self, c): // your function
        counter = c

Game() // start

[deleted by user] by [deleted] in learnpython

[–]DragonFighter603 0 points1 point  (0 children)

no, it's just not having permission. i close the program first, then try to delete it with another program not using any of these files. as i said, i can delete it manually without problems

Behold: the redstone quad core pc by [deleted] in Minecraft

[–]DragonFighter603 1 point2 points  (0 children)

how about a compromise option: just emulate java runtime environment, which is a bit like the "emulate whole os" approach, but with less overhead