Python Forum
Git clone all of a Github user's public repositories (download all repositories)
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Git clone all of a Github user's public repositories (download all repositories)
#21
I like it and it just barely passes pep8/pycodestyle... gonna push the change to the repository

Ah you mean

self.git_clone = "git clone https://github.com/%s/%%s.git" % user
Reply
#22
Quote:
self.git_clone = "git clone https://github.com/%s/%%s.git" % user
Why are you still using string expressions? Everyone uses format method now, and a lot are even using f-string above that.
https://python-forum.io/Thread-Basic-str...xpressions
Recommended Tutorials:
Reply
#23
No offense but the newer format method looks like garbage to me haha...

As far as readability goes... I don't like this (although I can see that it's powerful for formatting/aligning):

'some data: {2} {1} {0}'.format(1.4, 5, 'stringer')
I kinda like this one though:

site = '{w3}{0}{tld}'
>>> site.format('metulburr',w3='www.',tld='.com')
'www.metulburr.com'

Also I think that the older technique is very similar in many languages... definitely C and Go (both of which I use occasionally). Is there any real difference as far as performance goes? Or is just being used because it's easier to format? I think using % with column numbers is extremely easy to read, easy to use/format, and very similar across languages. Just my opinion though.

Also I think that if I showed two mildly complex print statements (one using the old style and one using the new style) to my PM on Monday (a non-programmer).... I'm pretty sure he's going to understand the old style based solely on intuition and third grade problem solving skills Big Grin
Reply
#24
Quote:Is there any real difference as far as performance goes? Or is just being used because it's easier to format?

Since string expressions were the main method in python2.x and 2.x is soon to be dead finally, since everyone is using python3.x now, that string expressions at some point might become obsolete and unsupported. If that does happen you would have to rewrite all your code to use at least the format method or force users to run an old version to support your string expressions. At this point it is not runnable in python3.x because everyone wants it, its mainly just for backwards compatibility. And it wouldnt surprise me that they remove it at some point in time.

Also by appearance, your code, since using string expressions looks old...meaning at first glance you would think your code only supports python 2.

Also I would call it unpythonic to use string expressions now. But that might be up to interpretation.

f strings are the even newer way in python 3.6+ would turn this
site = '{w3}{0}{tld}'
>>> site.format('metulburr',w3='www.',tld='.com')
'www.metulburr.com'
into this
>>> w3 = 'www.'
>>> name = 'metulburr'
>>> tld = '.com'
>>> site = f'{w3}{name}{tld}'
>>> site
'www.metulburr.com'
(Jul-20-2019, 05:20 PM)rootVIII Wrote: As far as readability goes
Thats odd. I find format method to be much more readable than string expressions. You are the first one i have heard to prefer string expressions over format.
Recommended Tutorials:
Reply
#25
Well that's a good point. But Python2 sometimes gives warnings that the os.popen() method will soon be obsolete, and I've seen other moderators on this site still using it... but it hasn't gone obsolete (and I don't think it really will). Although I think popen2-4() are gone...

And most code that I use in production does not use print statements, it uses logging. Although yes some stuff on my personal github would need to be redone. I guess I just tend to like things that are more universal. And for me the old string formatting technique is fast and easy.

I still might try use the newer format method to get used to it as I do see other programmers at work using it. Thank you for the link as it points out the variations pretty nicely.
Reply
#26
i like the way f-strings are expressed though i wish they had done them earlier, like way back in 2.6.0. and, i wish there was a short named method to do it at run time (i presume the pre-compiler is making code to do it, now) like: mystring.f() with optional namespaces or a list of namespaces to look in, instead of just local. i won't use f-strings in code i might release for the public until everyone is running 3.6 or later.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#27
Warnings are there for a reason. It will take time, but it will happen.

(Jul-20-2019, 06:23 PM)rootVIII Wrote: And most code that I use in production does not use print statements, it uses logging.
printing has nothing to do with it. You can format a string using string expressions to use it in logging as well.

(Jul-20-2019, 06:23 PM)rootVIII Wrote: I guess I just tend to like things that are more universal.
I can understand how when using different languages, to keep consistency helps. I dont mean to bash your method. I just figured i would give my 2 cents about it.
Recommended Tutorials:
Reply
#28
what seems, to me, to be happening with f-strings is that the compile phase is breaking it down to code (ultimately to byte code, if not directly) that builds the result string, which can then be used as a string value such as an assignment, a function/method argument, a dictionary lookup, or for an operator that can take a string. IoW, it results in a string that is formatted efficiently. i do wish there was a str method to do this at run time, though that would not be as efficient unless it can generate and cache byte code like a JiT system.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#29
for the logging.. yes.. actually now that I think about it a lot of it is still string formatted. If the old string formatting was removed, would something like this be invalid too?

formatter = logging.Formatter("%(asctime)s;%(levelname)s;%(message)s")
I definitely use this technique in all of my logging.

I would hope that the community would complain and argue to keep it, but maybe they wouldn't.
Reply
#30
there would continue to be some way to do formatting in functions and methods, even if it means another module to import and use ... i am sure. not doing so would break a lot of stuff.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pong clone with classes OhNoSegFaultAgain 1 3,890 May-11-2019, 07:44 PM
Last Post: keames

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020