Jump to content


Photo

learning python, join me if you'd like


  • Please log in to reply
29 replies to this topic

#1 postSingularityHumanoid

postSingularityHumanoid

    Anti-Brag Queen

  • Patron
  • PipPipPipPipPipPip
  • 64359 posts
  • LocationLimbo

Posted 21 January 2023 - 04:57 PM

So I've dabbled in python but since I never went through and learned it properly it was always a PITA to do anything because I'd have to do a lot of googling.  So now I'm trying to learn in a more organized way.  If anyone here would like to join me or just join in in this thread if you are more knowledgeable about python please by all means do so.

 

I'm currently reading through this beginners guide:  https://thepythonguru.com/

 

This is all easy stuff for me so far but it's still a lot of stuff I'd have to look up.  Like I know there is "something like that" but I would need to look up "exactly how to do that".

 

In any event there are a couple of things I'm not liking so far but I'm sure I'll get used to.

 

 

slicing:

includes the first index but not the last one?  wtf, python?  fuck you because that's going to be annoying for a while.

 

in:

so they show me "in" as in "is this in that, true or false?"  cool.  makes sense.  then they show me "in" in a for loop and now it is suddenly something else.  it's now a way to iterate through a list?  See example below:

 

>>> list = [1,2,3,4,5]
>>> for i in list:
... print(i, end=" ")
1 2 3 4 5

 

"i" wasn't previously defined below so it's not like it's a checking if "i" is in the list. that's fucking stupid.  why do that?

 



#2 dagomike

dagomike

    Comptroller of CrapPapples

  • Patron
  • PipPipPipPipPip
  • 17617 posts

Posted 21 January 2023 - 05:00 PM

Is learning python is the title of your sex tape?



#3 postSingularityHumanoid

postSingularityHumanoid

    Anti-Brag Queen

  • Patron
  • PipPipPipPipPipPip
  • 64359 posts
  • LocationLimbo

Posted 21 January 2023 - 05:05 PM

Is learning python is the title of your sex tape?

 

in



#4 postSingularityHumanoid

postSingularityHumanoid

    Anti-Brag Queen

  • Patron
  • PipPipPipPipPipPip
  • 64359 posts
  • LocationLimbo

Posted 21 January 2023 - 05:11 PM

append seems superfluous given that extend exists.



#5 Stains_not_here_man

Stains_not_here_man

    Phat O'Mic Chef Winner!

  • Patron
  • PipPipPipPipPipPip
  • 105019 posts

Posted 21 January 2023 - 05:22 PM

"for each" loops like that are actually one of the most useful constructs imo

#6 postSingularityHumanoid

postSingularityHumanoid

    Anti-Brag Queen

  • Patron
  • PipPipPipPipPipPip
  • 64359 posts
  • LocationLimbo

Posted 21 January 2023 - 05:31 PM

"for each" loops like that are actually one of the most useful constructs imo

 

agreed that is useful but there was no need to have "in" mean 2 different things like this.

 

could have just made it something like

 

for i = list:

    stuff happens involving i



#7 postSingularityHumanoid

postSingularityHumanoid

    Anti-Brag Queen

  • Patron
  • PipPipPipPipPipPip
  • 64359 posts
  • LocationLimbo

Posted 21 January 2023 - 05:38 PM

this is a new style of syntax with for loops I wasn't expecting.  here was my mental progression....

 

>>> list1 = [ x for x in range(10) ]
>>> list1
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

 

 

what's that first x before the "for" for?

 

>>>
>>>
>>> list2 = [ x + 1 for x in range(10) ]
>>> list2
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

 

oh?  it's like that x (now x+1) is IN the for loop.

>>>
>>>
>>> list3 = [ x for x in range(10) if x % 2 == 0 ]
>>> list3
[0, 2, 4, 6, 8]

 

wtf?  I can just "and" on a boolean expression to the for loop statement?  okay, I guess.

>>>
>>>
>>> list4 = [ x *2 for x in range(10) if x % 2 == 0 ]
[0, 4, 8, 12, 16]

 

both at once.  okay.

 

 

 

so that was just weird.  I'm used to:

 

for <iterate through something>

    <do something, maybe using the iterated value>



#8 TonyBrown

TonyBrown

    Comptroller of C-Blocking and Wet Streak Marks

  • Members
  • PipPipPipPipPipPip
  • 81907 posts
  • LocationRedneckistan

Posted 21 January 2023 - 08:02 PM

Came here for more silly walks

#9 badogg

badogg

    Comptroller of jokes about violence against women

  • Patron
  • PipPipPipPipPip
  • 30750 posts
  • LocationRight behind you!

Posted 21 January 2023 - 11:37 PM

Want to check out some real wackyness? Check out Haskell.

I can usually make sense of most languages code, but I just cannot get a grip on Haskell.

#10 postSingularityHumanoid

postSingularityHumanoid

    Anti-Brag Queen

  • Patron
  • PipPipPipPipPipPip
  • 64359 posts
  • LocationLimbo

Posted 22 January 2023 - 06:52 AM

I like how you can declare default values for variables right in the function definition.  handy!

 

def func(i, j = 100):
    print(i, j)



#11 Enid Puceflange

Enid Puceflange

    Old Squinty

  • Members
  • PipPipPipPip
  • 9467 posts

Posted 22 January 2023 - 08:13 AM

I like how you can declare default values for variables right in the function definition.  handy!

 

def func(i, j = 100):
    print(i, j)

So for me (C/C++ for the last 30 years or so) Python is just warmed up Basic - interpreted and no pointers - so slow and hard to do stuff. I might give it another chance tho because it is pretty much the native language of the Raspberry Pi which I love deeply and it does have lots of libraries that let you do cool stuff with scraping web pages etc.

 

We use Lua a lot if we're looking for a scripting language and that seems pretty irritating syntax-wise (rules just because) and Javascript which I always fall into the trap of treating just like C++ which it is right up to the point where it isn't.....



#12 postSingularityHumanoid

postSingularityHumanoid

    Anti-Brag Queen

  • Patron
  • PipPipPipPipPipPip
  • 64359 posts
  • LocationLimbo

Posted 22 January 2023 - 08:32 AM

I won't be missing pointers! I've been using Matlab for a long time now so python is at about the level of abstraction I'm comfortable with.

 

C/C++ was a long time ago.


Edited by postSingularityHumanoid, 22 January 2023 - 08:35 AM.


#13 postSingularityHumanoid

postSingularityHumanoid

    Anti-Brag Queen

  • Patron
  • PipPipPipPipPipPip
  • 64359 posts
  • LocationLimbo

Posted 22 January 2023 - 08:40 AM

I'm a little confused by this one.  Previous to seeing this snippet of code lines of text from a file were obtained by using read, readline or readlines.  Now the statement in that for loop reads a line without a function call???

 

>>> f = open('myfile.txt', 'r')
>>> for line in f:
... print(line)
...
this first line
this second line
this is third line

>>> f.close()



#14 Beejus McReejus

Beejus McReejus

    Comptroller of Flying Ducks

  • Patron
  • PipPipPipPipPip
  • 12328 posts
  • LocationTopeka, KS

Posted 23 January 2023 - 11:33 AM

I don't have much to add here, other than I took a python class a couple semesters ago for muh college learninz.  I aced the class, and only had one project that I struggled with (poor instructions from the instructor more than anything), but I have pretty much forgotten it all.  :P  If I don't use it on the reg, it tends to fall out of my head these days.



#15 postSingularityHumanoid

postSingularityHumanoid

    Anti-Brag Queen

  • Patron
  • PipPipPipPipPipPip
  • 64359 posts
  • LocationLimbo

Posted 24 January 2023 - 10:22 AM

so I used a regular expression in the project I've made up for myself but these things seem like more trouble than they are worth.  I have yet to find a website that does a good thorough explanation that builds up.  Much easier to understand if I do things the caveman way.



#16 Stains_not_here_man

Stains_not_here_man

    Phat O'Mic Chef Winner!

  • Patron
  • PipPipPipPipPipPip
  • 105019 posts

Posted 24 January 2023 - 10:57 AM

Loves me some regular expressions but it's a pain in the ass with all the different "flavors"

#17 postSingularityHumanoid

postSingularityHumanoid

    Anti-Brag Queen

  • Patron
  • PipPipPipPipPipPip
  • 64359 posts
  • LocationLimbo

Posted 24 January 2023 - 11:02 AM

Loves me some regular expressions but it's a pain in the ass with all the different "flavors"

 

the issue to me seems that by the time I figure out how to translate what my brain wants to a regular expression I could have written some for loops or something and been done already.

 

part of this is I don't quite get what all of the re functions are doing exactly.  some of the online tutorials show some things but they are so far from complete it's not enough without me needing to basically do trial and error to determine how things work.

 

 

let's say I had a list of words and I wanted to find all of the words that contained both the letter "a" and the letter "b".  how would you do that?  I'm assuming everyone imports re to do this stuff?

 

as it stands I just ended up going through the whole list of words with a for loop and making sure the word contained both "a" and "b" somewhere in it before adding it to my new list.


Edited by postSingularityHumanoid, 24 January 2023 - 11:07 AM.


#18 postSingularityHumanoid

postSingularityHumanoid

    Anti-Brag Queen

  • Patron
  • PipPipPipPipPipPip
  • 64359 posts
  • LocationLimbo

Posted 24 January 2023 - 07:34 PM

Stain?

#19 badogg

badogg

    Comptroller of jokes about violence against women

  • Patron
  • PipPipPipPipPip
  • 30750 posts
  • LocationRight behind you!

Posted 24 January 2023 - 09:22 PM

Looks like you want to use the square brackets for your search string according to this page: https://www.programi...unsuccessful.")

#20 Stains_not_here_man

Stains_not_here_man

    Phat O'Mic Chef Winner!

  • Patron
  • PipPipPipPipPipPip
  • 105019 posts

Posted 24 January 2023 - 09:35 PM

Right, so I'm not a python guy per se but I guess you'd set your 'pattern' = [ab] and then compare your strings against that and add them to new list if you get a match.

I use them a lot at work in the context of searching logs for specific patterns, like if I'm looking for all the lines in a file that contain some string like SESS-12A and SESS-99C and so on I can do a match on something like "SESS-\d\d\w" and easily find what I'm looking for.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users