Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Tacos Al Pastor
Jun 20, 2003

Having a bit of an argument with a friend regarding private functions in Python. He believes they cant be done. I indiciated that a class that contains a private copy of a method techincally is a private function, like the example in section 9.6 here: https://docs.python.org/3/tutorial/classes.html#tut-private.

Please convince me Im either right or wrong :D

PS this all goes back to an ADT argument where ADTs are not implemented the same on Python as say, C.

Adbot
ADBOT LOVES YOU

Tacos Al Pastor
Jun 20, 2003

Thanks for the feedback. I think I have a little better idea what is going on.

Tacos Al Pastor
Jun 20, 2003

Maybe this doesnt belong here but it is python related so here it goes: How do I use a conditional within a regex expression? The string is like this:

{some text} {timestamp in the form: '12:22:59:987654'} {more text} {text I want to match} {numerical data}

I only want to pull timestamps for the text I want to match.

Im using this regex string to pull the timestamp: r'\d{2}:\d{2}:\d{2}.\d{6}

Never done this before so thought I would ask the group.

Tacos Al Pastor
Jun 20, 2003


Thats awesome, but I dont want to store them in a tuple but rather a list.

Tacos Al Pastor
Jun 20, 2003

necrotic posted:

Pass the tuple to list() then?

Yeah thats cool. I just want to store the time given certain text in the line of a file. An example is: '(\b\d{2}:\d{2}:\d{2}.\d{6}).+(\b[uplink]+\b)", the first part being the timestamp and the second part being the text I am interested in filtering by. Any subsequent lines that dont contain that text, im not interested in collecting. Its then those times I want to store in a list.

Adbot
ADBOT LOVES YOU

Tacos Al Pastor
Jun 20, 2003

^^ yes the format was a .log file. What I did was look for the specific text I wanted and then filtered out those timestamps into a list. Since I needed to do this twice (one for upload and another for download), I decided to have two seperate lists to read from. And yeah I was trying to see if I could extract only two specific strings from a line of text (which I learned can be done using groups).

The Fool posted:

iterate the lines, if it does't match it returns None, if it does it returns group(0) as a string, append to your list

Thanks for this. This is what I ended up doing after playing around with it for a while.

DELETE CASCADE posted:

yes but i want to embed all of my logic in the regex don't you see?

haha yeah this is what I wanted to do. I came to the point that regex and grouping only takes you so far.

Tacos Al Pastor fucked around with this message at 16:40 on Mar 5, 2024

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply