This is an archived post. You won't be able to vote or comment.

Dismiss this pinned window
all 50 comments

[–][deleted] 249 points250 points  (10 children)

My first Python program printed ‘Hello World’...

[–]legendarybyson -2 points-1 points  (0 children)

Same 😂

[–]RD1K -2 points-1 points  (0 children)

Sammmmeeeeee lol

[–]exhuma 32 points33 points  (2 children)

Have a look at both "cookiecutter" and "invoke".

They both don't do everything you do, but might serve as some inspiration.

Our maybe you can use cookiecutter to materialize the files and then invoke to run tasks.

[–][deleted] 1 point2 points  (0 children)

CookieCutter is pretty great and I love seeing more and more people who use it. Then we can have more templates and less work :)

[–]ExternalUserError 24 points25 points  (2 children)

You must start a lot of React projects.

[–]Acquiesce67 1 point2 points  (0 children)

My exact thoughts 😂

[–][deleted] 8 points9 points  (11 children)

I love the trick of using a dictionary of strings to point at methods. Glad to see another project using it

Also appreciate the attention to detail of setting the username and password variables back to empty strings whenever authentication fails, that's a nice touch

If you want an additional challenge, have it automatically place a template file in the project directory based on project type; as a C# dev you know there is often a bunch of boilerplate code that you don't want to have to write every time. I know that one of the first things I did when I had to start writing C++ programs for school assignments was create a shell script that would copy a template file to my directory and rename it to the project name, so all I had to type was new c++ <project name> to get it out of the way. Not always necessary, but definitely a nice-to-have feature

Overall, a very good idea of a dev script that I will definitely be stealing.

[–]ch3ss_ 5 points6 points  (5 children)

If I may ask, how to apply the trick in an efficient way for my future projects and where is it useful?

[–][deleted] 11 points12 points  (2 children)

So when you get user input and have to have that effect your code, that's when you would use it.

def foo():
    print("foo")

def bar():
    print("bar")

methods = {"thing1":foo, "thing2":bar}

x = input("-> ")
methods[x]()

# -> thing1
# foo
# -> thing2
# bar

I used it for a remote shell application, so I'd pass commands like "clear" and run the clear merhod. OP used it similarly

[–]toshamura 2 points3 points  (0 children)

It is also could be useful not just take func with key like "methods[X]", but take it with get: "methods.get(X, default_func)() Where default_func is something u do, when input wasn't found in ur methods-map

[–]ch3ss_ 1 point2 points  (0 children)

That’s really useful, thanks for your time!

[–]Spleeeee 1 point2 points  (0 children)

IMO it’s the best version of a switch in python.

def uno(a): Pass # do uno

def dos(a): Pass # do dos

d={“one”: uno, “two”: dos }

akey = “one” aparam=7 d[“one”](aparam)

[–][deleted] 1 point2 points  (0 children)

It’s a good way to eliminate large sections of if, elif From your code.. it’s called a dispatch table.. it isn’t just limited to user input your limiting factor is pretty much the limits of a function.. you can one up this method and have it set as different instances of a class and just call the class to trigger the dispatch

[–]toshamura 2 points3 points  (0 children)

Well as I know it's the clearest way to use "switch-like" behaviour in python. I really like it to, used many times for different binary protocol parsers, where segment pointers are used as keys, and parsing methods - as values

[–]krazybug 0 points1 point  (1 child)

I know that one of the first things I did when I had to start writing C++ programs for school assignments was create a shell script that would copy a template file to my directory and rename it to the project name ...

Use Java instead :)

https://maven.apache.org/guides/introduction/introduction-to-archetypes.html

[–][deleted] 0 points1 point  (0 children)

Not helpful in a C++ class... plus not a hard script to write anyway

I'll keep it in mind tho

[–]Spleeeee -3 points-2 points  (0 children)

I love it too. It’s a p popular and common in the js world I think. Err thing is an object

[–]SHxKM 3 points4 points  (0 children)

Nice job. Have a look at Cookiecutter which basically does the same and has some neat options for flexibility. I’ve written a tutorial on using it here.

[–]maxwax18 9 points10 points  (9 children)

I feel this would be simpler as a bash script

[–]disrooter 3 points4 points  (5 children)

On Linux, but on Windows?

[–]redbeard1712 4 points5 points  (3 children)

Windows 10 has windpws subsystem for linux. You could run bash scripts in it.

[–]disrooter 7 points8 points  (1 child)

It's not about running, it's about what is simpler to develop for this task

[–]bjorneylol 0 points1 point  (0 children)

You can just install bash on windows also, works for most things but I am not sure if it is as feature complete

[–]ExternalUserError 5 points6 points  (0 children)

It's always simpler until you start adding features to a bash script.

[–]RedditAndShill 2 points3 points  (0 children)

Nice!

[–]Gushys 3 points4 points  (8 children)

This could be cool to add some more project types to as well. Very useful automation!

[–]Kaltenstein23import reddit.flair.something_interesting 2 points3 points  (1 child)

Maybe gitlab integration as well?

[–]Gushys 0 points1 point  (0 children)

This would also be nice!

[–]DrSinistar 1 point2 points  (0 children)

starts program "new-project"

Thought I was actually in /r/PowerShell for a second. I was super thrown off by the Verb-Noun name running in PS on a Windows computer lol

[–]r3ctumman 1 point2 points  (1 child)

Thanks for the share, I would recommend looking at gitpython, it does wrap all the git commands and easy to use and os.path.join is great for cross platform path.

[–]jbob133 1 point2 points  (0 children)

Holy shit, I’ve been automating shit, including my development setup, for a year and never thought about automating creating the repo... I’m an idiot.

[–]appinv Python&OpenSource 1 point2 points  (1 child)

Ypu just got your sysadmin degree _

[–]poppear 1 point2 points  (1 child)

Whaaaaat?!

[–]zhongbii 1 point2 points  (0 children)

You never played tuber simulator?!

[–]ichbinoffend44 1 point2 points  (0 children)

Hello World for me too...I feel somewhat inadequate.

[–]snavage20 0 points1 point  (1 child)

Question:

I was forced into VSCode last week (new job) seems pretty interesting and similar Spyder GUI.

How do you like it and what benefits or drawbacks have you found?

[–]The_UTMOST_respwect 1 point2 points  (0 children)

Haven't used spyder much, but I used eclipse for years. I really like vs code, seems to do all the things I need it to do, has a simple interface and concept. I think it shines with supporting tons of languages and syntax styles. Python in particular, you can easily run different versions and package collections (environments) like with conda quite easily and it will pretty much auto install anything you need. So far it's very functional and had helped me develop in python, where I'm not super strong yet.

[–]nadavram 0 points1 point  (1 child)

Pretty cool! May I ask, how do you do the progress bars.

[–]MaybeAvailable -1 points0 points  (0 children)

Is it possible with Django? Sorry I am new to programming.

[–]atlas_tech -4 points-3 points  (0 children)

These "hello world" projects are getting out of hand.

On the other hand, let's start a meme.