Asked  7 Months ago    Answers:  5   Viewed   37 times

I have a function that returns information in seconds, but I need to store that information in hours:minutes:seconds.

Is there an easy way to convert the seconds to this format in Python?



You can use datetime.timedelta function:

>>> import datetime
>>> str(datetime.timedelta(seconds=666))
Tuesday, June 1, 2021
answered 7 Months ago

python3 is not Python syntax, it is the Python binary itself, the thing you run to get to the interactive interpreter.

You are confusing the command line with the Python prompt. Open a console (Windows) or terminal (Linux, Mac), the same place you'd use dir or ls to explore your filesystem from the command line.

If you are typing at a >>> or In [number]: prompt you are in the wrong place, that's the Python interpreter itself and it only takes Python syntax. If you started the Python prompt from a command line, exit at this point and go back to the command line. If you started the interpreter from IDLE or in an IDE, then you need to open a terminal or console as a separate program.

Other programs that people often confuse for Python syntax; each of these is actually a program to run in your command prompt:

  • python, python2.7, python3.5, etc.
  • pip or pip3
  • virtualenv
  • ipython
  • easy_install
  • django-admin
  • conda
  • flask
  • scrapy
  • -- this is a script you need to run with python [...].
  • Any of the above together with sudo.

with many more variations possible depending on what tools and libraries you have installed and what you are trying to do.

If given arguments, you'll get a SyntaxError exception instead, but the underlying cause is the same:

>>> pip install foobar
  File "<stdin>", line 1
    pip install foobar
SyntaxError: invalid syntax
Tuesday, June 1, 2021
answered 7 Months ago

One of the things about programming is that there is never just one way to do something. In fact if I were to set my mind to it, I might be able to come up with a dozen completely different ways to accomplish this. You're not missing anything if your code meets requirements.

For your amusement, here's a way to format up hours:minutes:seconds under Windows (elapsed is a double & represents number of seconds elapsed since... something)

sprintf_s<bufSize>(buf, "%01.0f:%02.0f:%02.2f", floor(elapsed/3600.0), floor(fmod(elapsed,3600.0)/60.0), fmod(elapsed,60.0));
Thursday, August 12, 2021
answered 4 Months ago

use the following to convert to a timestamp in python 2


Sunday, August 22, 2021
answered 4 Months ago

Your Android project in Eclipse ADT usually should have 2 files


<?xml version="1.0" encoding="UTF-8"?>


<?xml version="1.0" encoding="UTF-8"?>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry kind="con" path=""/>
    <classpathentry exported="true" kind="con" path=""/>
    <classpathentry exported="true" kind="con" path=""/>
    <classpathentry kind="output" path="bin/classes"/>

Once you correct them, your project is back standard Android project in Eclipse.

To use newer build system from Eclipse try Nodeclipse/Enide Gradle for Eclipse (marketplace)

Some screenshots for Gradle for Eclipse:

Monday, September 13, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :