- Strength to Increase Rep
- +4
- Strength to Decrease Rep
- -1
- Upvotes Received
- 7
- Posts with Upvotes
- 6
- Upvoting Members
- 6
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
Re: I absolutely love PyCharm, and would highly recommend it. | |
Re: There are several ways to do this, including dictionaries, loops, etc. A simple solution would be to use a DSU (decorate, sort, undecorate). Let's assume you have the following list: my_list = ["I like apples", "Remember to eat your greens", Drink plenty of water"] We can use the split() method … | |
Re: The **listdir()** function of the **os** module returns a list of all files in a given directory. If you combine that with the **fileinput** module's **input()** function, you can go over all the files in a given directory and replace whatever you wish. (hint: look at the *inplace* optional argument … | |
Hi Everyone. I'd appreciate your help writing better code. I have a list of ~1000 values: list_of_values = [0x123D, 0x844F, 0x33E9, ....., 0xFFFF, 0xFFFF, 0xFFFF] The last values in the list will always be 0xFFFF, but I don't know how many exactly. What I want is to get rid of … | |
Re: OP, I'm guesssing you have something like this (maybe more than 4 letters per item): list_of_hex = ['12AF', 'B3D9', 'A5CC', '6EA1\n', '298F', 'A005\n', ...] You want a new list of ints, but can't convert the items with the trailing '\n'. You could do several things, but here's a quick and … | |
Hi Everyone, I have a list of numbers I'm trying to write to a file, which I want to be a binary file. Here's my code: nums = [0x1234, 0x5678, 0xabcd, 63, 44] with open('filename', 'wb') as bin_file: for number in nums: bin_file.write(number) The problem is that I keep getting … | |
Re: It seems like you're returning a tuple and not a string. try this and see what happens: [CODE]for item in pairwiseScore("ATTCGT", "ATCTAT"): print(item)[/CODE] or maybe you could try returning str(return value) in the function itself. Good Luck. | |
Re: Try placing the next line at the beginning of your python script: [CODE]#!/usr/bin/env python[/CODE] Then just call the script from the terminal: [CODE]./path_to_script/script.py[/CODE] What happens? | |
Re: Have a look at the built-in split() method. It will allow you to create a list composed of the values you need - [url]http://www.tutorialspoint.com/python/string_split.htm[/url] to check if an indexed item is empty, you could try checking if item == " " Good luck. | |
Re: argv is a list containing the arguments passed to the python interpreter when called from a command line. For example, let's look at this script: [CODE] # test.py from sys import argv print(argv[0]) print(argv[1]) print(argv[2]) print(argv[3]) [/CODE] command line call: [CODE]test.py david 8 jenny[/CODE] output: [CODE]>>> test.py david 8 jenny[/CODE] … | |
Re: First of all let's deal with the ConvertEnglish() function: The argument will probably be an int ('Number'), and it seems like you just need to return [CODE]numEnglish[Number][/CODE] As for the englishDigits() function: You're first step is right - you should isolate the rightmost digit. The second step however should pass … | |
Re: Here's my quick and dirty solution: [CODE]list1= ['NNW 30', 'SE 15', 'SSW 60', 'NNE 70', 'N 10'] for index, item in enumerate(list1): if item.startswith('N'): list1[index] = "+" + item[-2:] elif item.startswith('S'): list1[index] = "-" + item[-2:] print(list1)[/CODE] Notice the use of startswith(), and the negative used to slice the letters … | |
Re: [CODE] [I][B]position=old_mark.index[old_mark][/B][/I] # are you sure old_mark has an index....? [/CODE] I'm not sure what you're trying to do here, but remember you can always replace the value in a dictionary pair by doing: [CODE]dic[old_key] = new_value[/CODE] Good luck :-) | |
Re: First things first, I would recommend opening files this way: [CODE] with open(filename) as file: """ Do some stuff """ [/CODE] This guarantees that no matter what happens with your code (unexpected error, hangs, etc.) the file will always be closed properly. As for the other tasks - once you've … | |
Hi Everyone :cool: What is the best way to represent, modify, and perform calculations with hexadecimal values (for instance, byte addresses) in Python? It seems every time I play with hex numbers, I'm always getting the result as a string or regular int type. case in point: Let's say I … | |
Hi Everyone :-) I'm writing a small Python script that invokes the Linux shell and runs some BASH commands in it. My problem is, I can't seem to use the output and store it in a Python variable. Here's what i'm trying: [CODE] import subprocess value = subprocess.call("ls -la", shell=True) … | |
Hi everyone, Just started programming in Python and iI'm already starting to like this language very much. I have a problem with a program I wrote last night - I'm trying to ping a certain host using [CODE]os.popen("ping xxx.xxx.xxx.xxx"[/CODE] and then read the %errorlevel% from my system using [CODE]result = … |