2,646 Posted Topics
![]() | Re: This question is a duplicate of [this one](http://stackoverflow.com/questions/25012886/plotting-3-columns-or-more-data-on-the-graph-python) in another forum. |
![]() | Re: I tried your code, and apparently it works: the decimal points are aligned. Can you post your output ? Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> num1 = 127.899 >>> num2 = 3456.148 >>> num3 = … |
![]() | Re: There are python modules to read xls files (such as xlrd). However in your case, it may be easier to convert the file to csv on the command line: if you have Libreoffice installed on your computer, you can use soffice --headless --convert-to csv data.xls in a terminal to convert data.xls … |
![]() | Re: I suggest using pandas dataframes and their methods for statistics # -*- coding: utf-8 -*- import pandas as pd df = pd.read_table( 'data.csv', sep=',', header=0, parse_dates = [0] ) print(df) m = df.mean() print(type(m)) print(m) print float(m['Irradiance']) """ my output --> 0 2014-07-21 00:00:00 0.66 1 2014-07-21 00:00:00 0.71 2 … |
![]() | Re: Install [humanfriendly](https://pypi.python.org/pypi/humanfriendly) from pypi (`pip install humanfriendly`), then from datetime import datetime from humanfriendly import parse_date s = raw_input('From datetime: ') dt = datetime(*parse_date(s)) print(dt) |
Re: Your code is very difficult to understand. I think you can do a lot with a single regular expression, like in this example # -*- coding: utf-8 -*- """ Created on Fri Jul 25 19:23:53 2014 python 2 or 3 @author: Gribouillis """ import re pattern = re.compile( r"^(?P<prefix>(?:[^_.]|_(?!p))+)" r"_p(?P<type>(?:[^_.]|_(?!b))+)" … | |
![]() | Re: Use time_format = '%d/%m/%Y %H:%M' try: datetime_obj = datetime.strptime(time_string, time_format) except ValueError: print("STRING: ", repr(time_string), "FORMAT: ", repr(time_format)) raise and post the output. ![]() |
Re: The csv module has a concept of *dialect*. For example in the data shown above, I don't see separating commas or quoting characters. See for [example here](http://www.daniweb.com/software-development/python/threads/443909/learning-re-module#post1912119) how one can use a dialect to read a csv file. Can you attach a short csv file to a post ? (perhaps … | |
This snippet defines a function [icode]mousepos()[/icode] which gets the mouse position on the screen. The package python-xlib is required. | |
Re: This thread is a duplicate of this one: [click here](http://www.daniweb.com/software-development/python/threads/482152/inserting-zeros-depending-on-the-length). Discussion goes on in the other thread. | |
![]() | Re: Did you try oldwd = os.getcwd() os.chdir('C:/Users/UserName/Documents') try: zipdir('Folder_to_be_zipped', zipf) finally: os.chdir(oldwd) ? |
Re: Here is a [tkinter example](http://www.daniweb.com/software-development/python/code/216830/tkinter-keypress-event-python) by vegaseat. | |
Re: Did you check the type of `line` ? it seems to me that is a `str` (which means unicode in python 3). Again you are mixing bytes and str implicitly (`tag in line.lower()`). Use explicit conversions to control the types. | |
Re: Try import eyeD3 To answer your second question, create for example a directory with $ mkdir ~/pymods in a terminal, then add the following lines to the file `~/.bashrc`, and restart the terminal PYTHONPATH="$HOME/pymods:$PYTHONPATH" export PYTHONPATH Now every python file added to the directory `~/pymods` becomes importable from anywhere (under … | |
Re: > In the spirit of more than one way to do it ... Notice that python came after perl, and in python, > There should be one-- and preferably only one --obvious way to do it. type import this in the python console to read the Zen of python. The … | |
Re: I think `logging.info()` should be `logger.info()`. | |
Re: One part of the question is why would we need an OS written in python ? My advice is: go linux ! | |
Re: As sepp2k said, create MyTime instances `t1 = MyTime(9, 59, 59)`, etc. | |
Re: This is the first [dadaist](https://en.wikipedia.org/wiki/Dada) thread here. Your code does not make sense. Do something useful instead ! | |
Re: Here is a short explanation about variable visibility varA = "foo" # a global variable class Bar: # Bar is another global variable varB = "baz" # a class variable def method(self, arg): # self and arg are local variables varC = "qux" # a local variable self.name = "aname" … | |
Re: The main concern is about encoding. If you know the file's encoding, you can open it with `codecs.open()` and read the file as a unicode stream. I never used a hindi file, so that you must figure out the encoding yourself. Once you have the correct unicode stream, the rest … | |
Re: Independantly from writing the code, you must first define your classification criterion: how will you decide if a file belongs to 'name' or 'english', or 'entertainment' ? | |
Re: It seems to me that `urlretrieve()` answers your question. For ftp, the example at the top of the `ftplib` module's documentation shows how to download a file named README. Also a search for `ftp` on pypi may reveal promising modules such as `ftptool` and others. | |
Re: First note that due to [operator precedence](https://docs.python.org/3.3/reference/expressions.html#operator-precedence) the expression A or B in C is the same thing as A or (B in C) In particular if A is a non empty bytes such as `b'artist='`, the value of the whole expression is `A`, which evaluates as `True` in a boolean … | |
Re: It is not true that `file`is a reserved word in python. `file` is the name of a standard type in python **2**. Using file as a variable name in python 2 is like using list as a variable name. It is not an error, but it could be annoying to … | |
Re: > In what way is the use of Parameters similar/different to Variables? Same thing? The correct python concept is the *namespace*. At any given moment in the execution of python code, a certain number of *names* are defined in the current namespace. There is no difference between parameters and variables … | |
Re: Why not use a decorator ? #!/usr/bin/env python # -*-coding: utf8-*- from __future__ import (absolute_import, division, print_function, unicode_literals) __doc__ = '''adding attributes to a function ''' def menu_config(**attrs): def decorator(func): func.menu_attrs = attrs return func return decorator @menu_config(Name = 'Test Menu', Default = True) def test(): print('foo') if __name__ == … | |
Re: Apparently, the whole code depends on 2 values, `fileFull` and `fileAbriv`. So you can write a function def func(fileFull, fileAbriv): etc However, this code, with lines repeated with different variable name case is not good. There must be some other way to write your code. Read about the [DRY](https://en.wikipedia.org/wiki/Don't_repeat_yourself) principle. … | |
Re: You're getting the error because `char` is of type `bytes`, and `char[counter]` is an integer. Also you initiliazed newchar as a `str`. At line 15, you can't add a str and an int. You could write newchar = b'' # initialize as bytes counter = 0 while counter < 30 … | |
Today is 70th anniversary of D-Day in France, with 20 heads of state, including Queen Elizabeth and Barack Obama ! Great weather and nice speeches ! https://twitter.com/FranceinChicago/status/474910715237502977/photo/1 Let's remember these 150000 soldiers ! http://online.wsj.com/articles/d-day-invasion-view-from-above-1402005875?tesla=y#1 | |
Re: First thing to do is to print the structure to see what it contains. I found a pretty printer [here](http://alexleone.blogspot.fr/2010/01/python-ast-pretty-printer.html) #!/usr/bin/env python # -*-coding: utf8-*- from __future__ import (absolute_import, division, print_function, unicode_literals) __doc__ = ''' ''' import ast from astpp import dump source = """ def foo(n): p = 1 … | |
Re: Add print(repr(word)) print(list) immediately before line 19 and post the output here. Also 'list' and 'dict' are so common words in python that nobody uses them for variables. | |
Re: The most famous place in France is the Eiffel tower (almost 7 million visitors a year), but it's not a place I would recommend. Start with the south of France. Edit: I forgot the Louvre museum with almost 10 million visitors/year. The atmosphere is that of a railway station with paintings … | |
Re: I'm not an expert but I think `geometry()` applies to top level windows only. You may want to call OedipusFrame.winfo_toplevel().geometry(("%dx%d+0+0")%(OFWidth,OFHeight)) See also [here](http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/geometry.html). | |
Re: Here are the [answers](http://bit.ly/1tum6qo). | |
Re: You can perhaps add the condition that there is no uppercase letter before the first 3 ones or after the 3 last ones. | |
Re: Python only wraps the lower level system functions which open a file to create a file descriptor or a pointer to file, and the corresponding read or write functions. So, for example you could ask in the C forum if `fopen()` with mode `'w'` physically overwrites existing contents on the … | |
Re: I think you must decode the crypted text contained in the html source page. | |
Re: `Plot` is deprecated (`pydoc sympy.Plot`). Use `plot` with small p instead. | |
Re: I see 2 tools which could give you more detail: 1. You can use `sys.settrace()` to define your own trace function and count the number of calls in each line (there is some programming effort to get something here). 2. You can use `f.f_lasti` on the calling frame to get … | |
Re: It is very nice. I see 2 directions onwards: 1. Add interaction with the user to get the coefficients (raw_input, etc). 2. Use the fractions module from standard lib to work with exact rational coefficients. | |
Re: The simplest way is import easygui word = easygui.passwordbox() You can then browse the easygui source code to learn how to make a passwordbox :) and remove the buttons if you want to. | |
Re: Your explanation is unclear. I don't think there is an issue. For example if the first file contains args = parser.parse_args() you can later call `foo(args)` and it doesn't matter if function `foo()` was defined in the first or the second script. | |
Re: The best thing to do is to add `print(args)` to your script and test it in a console with commands such as $ python filename.py -h $ python filename.py -b /home/foobar I would add a long name such as `'--basepath'` to the `'-b'` option and use `BASEPATH` as metavar. Also … | |
This snippet implements a pointed set, that is to say an ordinary set of elements with a distinguished element called the basepoint of the set. For example the seven days of the week could be stored in a pointed set, the basepoint being monday because today is monday. It is … | |
Re: May I suggest that you install [locate32](http://www.windows8downloads.com/software-search.html?keywords=locate32&Search=) to find your files in win 8 ? | |
Re: My father in law bought an asus which broke down rapidly. On the other hand, I had one which worked very well during almost 10 years. I bought 3 acer aspire laptops for 500/700 euros in the last 2 years, and they do their job. The first thing I do is … | |
Re: Sorry I only have python-wxgtk2.8 in kubuntu :( | |
Re: You can use cnt = sum(1 for line in open("foo.csv")) | |
Re: I would go with BeautifulSoup as it produces short code, for example # -*-coding: utf8-*- from __future__ import (absolute_import, division, print_function, unicode_literals) from BeautifulSoup import BeautifulSoup def main(): filename = 'input.xml' soup = BeautifulSoup(open(filename).read()) for channel in soup.findAll('channel'): cid = channel['id'] # or dict(channel.attrs)['id'] for prog in channel.findAll('programme'): for title … |
The End.