-
Replied To a Post in lamda expression to match beginning of line with any digit
You can use `lambda line: bool(re.match(r"^\d", line))`, but following woooee's idea of not using lambda, you can also write def starts_with_digit(line): return bool(re.match(r"^\d", line)) RDD2 = RDD1.filter(starts_with_digit) -
Gave Reputation to snippsat in lamda expression to match beginning of line with any digit
Why lambda expression? It can make code less readable. > All you should need to do is import string and apply in to your string's first character, and string.digits, and … -
Replied To a Post in how open .tdb files?
I have only a tdb file with one key to make tests, but you can explore the database once in the tdbtool interpreter. Simply use the available commands. Here is … -
Replied To a Post in how open .tdb files?
I never used it but it seems that you must write tdbtool open group_mapping.tdb or perhaps tdbtool and then `open group_mapping.tdb`. -
Replied To a Post in grub
I cannot solve your issue, but I used [boot-repair](http://sourceforge.net/projects/boot-repair/) recently to restore broken boot configurations and it worked each time. In ubuntu, or live ubuntu, you can install boot-repair with … -
Replied To a Post in Which is your favourite Linux distro and why?
Nobody has yet invented the "facade" linux OS which would lazily install apps the first time they are opened. Note that kubuntu is close to this when one invokes a … -
Replied To a Post in XML file searching
It means that none of the calls to `.find()` finds anything. -
Replied To a Post in input list being modified in error
> thanks, but it only needs to shift the supplied list_in, no need for an infinite sequence I don't completely agree with you. See the following example which shows a … -
Replied To a Post in input list being modified in error
> offset = offset % len(list_in) This applies an offset *modulo* the length of `list_in`. For example if the list has length 6, it will apply an offset in the … -
Replied To a Post in Which is your favourite Linux distro and why?
I started with slackware about 20 years ago, then Red Hat, then Mandriva, until it died, but today, my favorite distro is Kubuntu because it works flawlessly. Kubuntu 14.04 LTS … -
Replied To a Post in input list being modified in error
I would do it this way >>> def shift_right(list_in, offset): ... offset = offset % len(list_in) if list_in else 0 ... return list_in[-offset:] + list_in[:-offset] ... >>> one = [1,2,3,4,5,6,7] … -
Replied To a Post in Data upload
Upload to where ? There is no general solution. It depends on the receiving site or computer. -
Replied To a Post in filtering normal readable text from junk
In linux you could use a command line such as lynx --dump URL to get a textual version of the web page. Here is what it does to this page … -
Replied To a Post in Convert python examples to runnable code.
Following the previous remark, here is the new version of script_from_example.py, which should work for standard console output and also for idle output, and even ipython output (but you must … -
Replied To a Post in how open .tdb files?
On my `.tdb` files, the 'file' command gives TDB database version 6, little-endian hash size 999 bytes The correct command seems to be [tdbtool](http://www.tutorialspoint.com/unix_commands/tdbtool.htm) -
Gave Reputation to Mocabilly in how open .tdb files?
They are probably some sort of dbase files. To determine the file type, you can use the "file" command. file foobar.tdb If you are sure of the file type you … -
Replied To a Post in tkinter - binding key commands to the numpad in windows
Did you check [this code](http://tkinter.unpythonic.net/wiki/EnhancedText) which apparently implements playing with the arrow keys and the numpad to move the cursor in a text widget ? It could be a starting … -
Gave Reputation to TrustyTony in Convert python examples to runnable code.
Looks like the doctest can not handle def statements from log of IDLE command prompt. [CODE]C:\py>script_from_examples.py ex2.txt def sum(a,b): # Expected: ## return a+b C:\py>type ex2.txt >>> def sum(a,b): return … -
Replied To a Post in Convert python examples to runnable code.
> Looks like the doctest can not handle def statements from log of IDLE command prompt. It is true, but I finally found a solution for idle. There is an … -
Replied To a Post in how open .tdb files?
In kubuntu, I also found sudo aptitude install tdb-tools tdbdump FOOBAR.tdb # prints database contents to console -
Replied To a Post in how open .tdb files?
On my computer, I found .tdb files in `~/.config/pulse` and `~/.cache/rhythmbox/album-art`. There is also a module `python-tdb`. I was able to open my tdb files in the python interpreter: import … -
Replied To a Post in cannot import books from NLTK.
Assuming you can `import Tkinter`, type >>> import nltk >>> nltk.download() in the GUI which appears, select `Everything from the nltk book` and click download. Wait. -
Replied To a Post in Looking for numbers in file name
Simplicity is in the eye of the beholder ;) -
Replied To a Post in Looking for numbers in file name
Here is a progran to create an example hierarchy of folders and search a correct folder. The idea is to extract a pair of numbers from the names and compare … -
Replied To a Post in Looking for numbers in file name
This does not tell us which one is the correct subfolder and why. We don't have the names of the folders. -
Replied To a Post in Looking for numbers in file name
Perhaps you could describe a small hierarchy of folders, then tell us which one is *the good one* and why, assuming that you are searching a single folder in the … -
Replied To a Post in Looking for numbers in file name
> how do i get it to retunr the largest of the numbers cuase i ran it on the files i have which are 08-1, 8-02, 8-3, and 08-04 it … -
Replied To a Post in Assigning datatype to variable in python
I don't know a lot of Qt, but [this tutorial](http://www.pythoncentral.io/pysidepyqt-tutorial-creating-your-own-signals-and-slots/) says that you can pass any python types to `Signal()`. From the interpreter's point of vue, there is no difference … -
Replied To a Post in Looking for numbers in file name
Instead of `getints()`, define your own score function def score(dirname): """return a value extracted from the dirname""" value = ??? # your code here return value thedir = max(L, key=score) -
Replied To a Post in Looking for numbers in file name
In python, *the largest of* a sequence can be obtained with the `max()` function with a key argument to compute the score of an item. >>> import re >>> def … -
Replied To a Post in how to match paricular string by using python
I think you misunderstand the meaning of the raw strings. The important point is the sequence of characters that the string contains. You can see it by converting to a … -
Replied To a Post in Looking for numbers in file name
Another way, returning a list of integers >>> import re >>> def getints(string): ... return [int(x) for x in re.findall(r'\d+', string)] ... >>> getints("foo23bar01-14qux2") [23, 1, 14, 2] -
Gave Reputation to jamercee in Code signing python scripts.
I know this is an old post, but we've developed a new solution. We were confronted with the same challenge -- to distribute python source code, but to prevent hackers … -
Replied To a Post in ubuntu screen resolution problem after first install alongside windows xp
Did you try to query and change the screen resolution with the xrandr command ? See [this blog entry](http://blog.bodhizazen.net/linux/use-xrandr-to-set-a-screen-resolution/) for example. If a command line with xrandr works, you could … -
Replied To a Post in Scripting
Use this python script #!/usr/bin/env python #-*-coding: utf8-*- import argparse import os if __name__ == '__main__': parser = argparse.ArgumentParser(description='chmod files to mode 744') parser.add_argument('files', nargs='+', metavar='FILES') args = parser.parse_args() for … -
Replied To a Post in Csv file writing multiple times
Replace the blocks for item in data: writer.writerow(data) with writer.writerow(data) -
Replied To a Post in Adding to a mysql database using tkinter with python
I suggest to execute sql queries on the database using module MySQLdb. -
Replied To a Post in Plotting 3 columns or more data on the Graph (python)
> oh ok since i never copy anyone content, guess i'm fine? It's not really the question. As a helper, I think it is useful to know that you are … -
Replied To a Post in Plotting 3 columns or more data on the Graph (python)
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. -
Gave Reputation to woooee in Decimal formatting
"Aligning" depends also on the font used. If you are displaying the result in the console, then the console must use a fixed witdth font. If you want to experiment, … -
Replied To a Post in Decimal formatting
I could not reproduce the bug. Here is my idle3 screen: Oh, I see that you solved the issue. Great! -
Edited Decimal formatting
In my python class, we are using python 3.4.1 And we are typing in the programs from the book. Well, I've typed it in correctly and the output still doesn't … -
Replied To a Post in Decimal formatting
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 … -
Replied To a Post in (Python) Reading/Converting xls file to txt file
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 … -
Replied To a Post in Parsing large text file in Python
You can use [string operations](http://zetcode.com/lang/python/strings/) to create the lines of output. -
Replied To a Post in Parsing large text file in Python
Using `readlines()` is a bad idea as it reads the whole file in memory. You could try something like the following code, which loads one line at a time #!/usr/local/bin/python2.7 … -
Replied To a Post in Finding Mode/Average in Txt File Data (Python)
You must not copy and paste code verbatim without understanding it. If your data file is named `data.txt` instead of `data.csv` for example, you must adapt the code. The question … -
Replied To a Post in Finding Mode/Average in Txt File Data (Python)
Here is what I found # -*- coding: utf-8 -*- import datetime as dt import pandas as pd df = pd.read_table( 'data.csv', sep=',', header=0, parse_dates = [0], index_col = 0, … -
Replied To a Post in Asking User For Input Before Plotting Selected Points
I don't think you can do that with matplotlib. You'll have to use one of the gui toolkits to build a dialog widget. -
Replied To a Post in Finding Mode/Average in Txt File Data (Python)
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) …
The End.