Questions tagged as 'python-2.7'

2
answers

Printing specific lines from a text file

Imagine that I have a text file called test.txt with the following content: 4 Março 2017- Sábado meu aniversario -prova de calculo 6 Março 2017- Segunda aniversario do Salomao - fazer compras 8 Março 2017- Qu...
asked by 12.03.2017 / 02:46
2
answers

Remove non-numeric characters from a string in Python

Let's suppose, I have: a = "0LÁM@UN@D0 I would like something that removes all the letters (A-Z) and other characters, I just want the numbers to stay in the example, it would only be 0 and 0 b = "A1B2C3" Something that takes away the...
asked by 12.11.2017 / 19:04
3
answers

Doubt with Python's str.replace () method

I have the following text:    'box 1 is blue, box 10 is green, box 100 is empty' I want to replace 'box 1' with 'package 2', so I do: >>> texto = 'caixa 1 é azul, caixa 10 está verde, caixa 100 está vazia' >>> print(te...
asked by 30.08.2015 / 19:49
1
answer

Working @classmethod

I'd like to get a better understanding of the @classmethod annotation of Python. Briefly, it works as a second constructor alternative. But what are the benefits? When to use? @classmethod def from_teste(cls, teste): How does cls...
asked by 08.04.2015 / 21:03
2
answers

Start a command line tool in Python

How can I create a command line tool in Python that works like ls of Linux or dir of Windows? How would I start a script like the one that will later be compiled as an executable?     
asked by 01.08.2016 / 21:55
2
answers

Create vector automatically in Python

I'm new to Python and need help with the following: I have a variable (x) that gets an integer value. I want this variable to be used to create a vector with 1 row and (x) columns. This vector must have random integer values from 0 to 10...
asked by 23.04.2017 / 20:34
2
answers

Checking a DoS / DDoS (Denial of Service) attack on a network dump (PCAP file)

from scapy.all import * import dpkt f1 = open("semAtaque.pcap") pcap = dpkt.pcap.Reader(f1) f1.close() f2 = open("Ataques.pcap") pcap = dpkt.pcap.Reader(f2) f2.close() I have two network traffic captures for a lab experiment: one free of att...
asked by 10.03.2017 / 18:51
1
answer

Error TypeError: a float is required

This is my code: ### BIBLIOTECAS import scipy.special as sps import numpy as np import matplotlib.pyplot as plt import pandas as pd import scipy as sp from scipy.stats import norm from scipy.stats import gamma from math import exp import oper...
asked by 23.12.2016 / 13:16
4
answers

Place items in lists

I would like to have two lists: one with the name of the fruit and another with the colors. lista = ['banana [amarela]\n', 'uva [vinho]\n', 'laranja [laranjado]\n', 'kiwi [verde]\n', 'framboesa [vermelho]\n', 'coco [marrom]\n'] lines = lista....
asked by 13.09.2017 / 15:32
1
answer

Open multiple files with "with open"

You can open more than one file in a program with with open("meutexto.txt", "r") as f: I did not find anything about it (or did not look right). I know you can do it differently: var = open("meutexto.txt", "r") var_dois = open("meu_segund...
asked by 04.09.2017 / 11:55