Python or C++

Associate
Joined
6 Jun 2016
Posts
164
Location
Cambridge
Here is a Python equivalent taken from Python Cookbook by David Ascher, Alex Martelli


Code:
# needs win32all, or ActiveState's ActivePython distribution
import win32serviceutil

def service_running(service, machine):
    return win32serviceutil.QueryServiceStatus(service, machine)[1] == 4

def service_info(action, machine, service):
    running = service_running(service, machine)
    servnam = 'service (%s) on machine(%s)'%(service, machine)
    action = action.lower(  )
    if action == 'stop':
        if not running:
            print "Can't stop, %s not running"%servnam
            return 0
        win32serviceutil.StopService(service, machine)
        running = service_running(service, machine)
        if running:
            print "Can't stop %s (???)"%servnam
            return 0
        print '%s stopped successfully' % servnam
    elif action == 'start':
        if running:
            print "Can't start, %s already running"%servnam
            return 0
        win32serviceutil.StartService(service, machine)
        running = service_running(service, machine)
        if not running:
            print "Can't start %s (???)"%servnam
            return 0
        print '%s started successfully' % servnam
    elif action == 'restart':
        if not running:
            print "Can't restart, %s not running"%servnam
            return 0
        win32serviceutil.RestartService(service, machine)
        running = service_running(service, machine)
        if not running:
            print "Can't restart %s (???)"%servnam
            return 0
        print '%s restarted successfully' % servnam
    elif action == 'status':
        if running:
            print "%s is running" % servnam
        else:
            print "%s is not running" % servnam
    else:
        print "Unknown action (%s) requested on %s"%(action, servnam)

if _ _name_ _ == '_ _main_ _':
    # Just some test code; change at will!
    machine = 'cr582427-a'
    service = 'Zope23'
    action = 'start'
    service_info(action, machine, service)
 
Soldato
Joined
6 Mar 2008
Posts
10,078
Location
Stoke area
https://www.humblebundle.com/books/...ayout_index_2_layout_type_threes_tile_index_2

is this worth the 12 quid for someone whes done a little linux shell based coding to achieve a simple task but would like to expand into something more purposeful.

Spent many years on a support desk but ideally would like to expand into a devops type role eventually

Myself and quite a few of the mods on our Python groups have invested in them. There's a lot of info there for the £12.
 
Soldato
Joined
25 Jun 2011
Posts
5,468
Location
Yorkshire and proud of it!
https://www.humblebundle.com/books/...ayout_index_2_layout_type_threes_tile_index_2

is this worth the 12 quid for someone whes done a little linux shell based coding to achieve a simple task but would like to expand into something more purposeful.

Spent many years on a support desk but ideally would like to expand into a devops type role eventually

Probably, as it's very cheap. But don't be fooled by the volume of books. I'd never have time to read through all that and I doubt most people would. Better to get one very good book than a dozen okay books. The O'Reilly Python Cookbook is good, imo. (I have it). And you could get a slightly older version second hand, I imagine. Get something that targets Python 3 as there are significant differences between versions 2 and 3 of Python.

You wouldn't go wrong just working your way through the documentation and tutorials on the Python website, tbh. If you finish those, THEN look at a good book on a specific area or a Python Cookbook.
 
Associate
Joined
28 Mar 2019
Posts
1,117
Location
Channel Islands
Most languages such as javascript, c#, c, java ect. Have a "C like" syntax. As such I would advise learning C++.
Python is a weird one as it tends to box you into that language due to the weird white space syntax.

Unless you want python for a specific reason (of which there are many) I wouldn't learn it as a first language.
 
Soldato
Joined
30 Nov 2005
Posts
13,915
Learning to write code in python with its elegant use of white space, will mean when you start writing in other languages you can still write in an elegant fashion
 
Soldato
Joined
19 Oct 2004
Posts
4,214
Location
London
i've been interested in learning python as have wanted to have a go at programming since doing my Computer Science GSCE about a million years ago. My current job looks like it might wind down in a few years i fancy that if i get redundancy that might be a good time to re-train. i'd be happy to be low paid to start off with (especially if i could freelance or work from home around picking kids up from school), but how difficult is it to even get that job? i'm fairly mathsy and logical (i think) but is home learning - books and linked in learning and other online resources - really going to get me there or would i need to look at university (again) or are there other courses that would get me there?

If i wanted to make indie games for phones say would it be the right thing to use, or an i a million miles off?
 
Man of Honour
Joined
19 Oct 2002
Posts
29,524
Location
Surrey
It would be easier to find a job if you either had previous experience or had a degree. So it would be harder. But it's still possible. There is no harm trying to learn it now and then looking for jobs if needed later. You would obvipusly have to start as a very junior programmer with neither experience or a degree.

Python isn't used for phone app development. For that you would need Swift (iphones) or either Java or Kotlin (Android).
 
Soldato
Joined
19 Oct 2004
Posts
4,214
Location
London
Thanks Hades. To be honest the games thing is probably a stupid idea anyway. Everyone knows how hard those guys have to work and how badly they get paid. Java does sound like an option too though
 
Man of Honour
Joined
13 Oct 2006
Posts
91,164
Thanks Hades. To be honest the games thing is probably a stupid idea anyway. Everyone knows how hard those guys have to work and how badly they get paid. Java does sound like an option too though

If you want to do indie game development (hobby or small commercial efforts of your own) for phones give Godot a gander - it is a little prohibitive at first to get to grips with but once you do (watching some YouTube videos on making simple games from scratch is highly recommended) seems quite reasonable for producing cross platform games with minimal understanding of the platform specifics and with little more than basic programming experience.

(Probably not so helpful if you want to build up the experience to work in a studio that produces games though).
 
Man of Honour
Joined
19 Oct 2002
Posts
29,524
Location
Surrey
Thanks Hades. To be honest the games thing is probably a stupid idea anyway. Everyone knows how hard those guys have to work and how badly they get paid. Java does sound like an option too though
For pure Android drvelopment I would recommend Kotlin over Java (in a similar way that Objective C was phased out in favour of Swift on iOS).

However Java is more widely used than Kotlin on non-Android development. So Java would be more useful if you are hoping to one day work for a large enterprise company.
 
Last edited:
Associate
Joined
17 Apr 2018
Posts
905
For Android Development I would learn Java first and then Kotlin as there are a lot functions that are still java and it gets a bit confusing at times when declaring the function in Kotlin and there are more resources/examples available in Java than Kotlin(not yet anyway).
My uni project was Java and my previous app that I help work on with my previous company and then my latest project with my current company I learnt and wrote in Kotlin and it can get confusing but it's a lot better programming language to work with.

The only nitpicking I have with Android Studio/Intellij vs XCode is when you're trying to find a function or declaring something to a variable there is no simple explanation what they are like there is on XCode.
 
Back
Top Bottom