Programming :: Python - Only Return Information For A Particular Function When A Flag Is Passed
Oct 28, 2010
I have a script that i want to add some functionality to, but im new to python. Right now it runs command line as ./script https://server user passwd verbose , which returns alot of informtion. I would like it to be able to only return information for a particular function when a flag is passed. exp: ./script https://server user passwd verbose -m (for memory only)
Under the ClassesToCheck section are the different things that can be retrieved. I would like that when you run the script as ./script https://server user passwd verbose -m, it returns only the 'Memory' info. -c would be for 'CPU', etc... Also, i would like the OK at the end of the script to be the first line that is return in the output instead of the last.
View 2 Replies
ADVERTISEMENT
Jun 13, 2010
But it's been hell finding an answer, or I just don't know what to look for..I have a prompt that asks for a float, and if the user doesn't put in a valid number, then it should die with an error message.
Code:
def die_with_error():
print 'ERROR: You didn't specify a valid number!'
[code]....
View 2 Replies
View Related
Mar 11, 2011
I'm trying to teach myself python (from Learn Python the hardway e-book) but am struggling to grasp the concepts of Classes etc. Part of exercise 43 is to rewrite the game / create a new game with classes for each room etc. So I'll show you my code so far and explain at the bottom my problem
Code:
#ex43a.py
from sys import exit
[code]....
View 2 Replies
View Related
Jun 10, 2010
Why do I see different values of character 'a', in main() and in functionA() in the following C++ code?
Code:
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
[Code]....
View 7 Replies
View Related
Apr 19, 2010
I am writing a game in C with SDL. I can successfully display one image on the screen and animate it. However, I am having a lot of issues getting the background to display using the same method. I was asking for help on SDL related forums, but I determined that the issue is not SDL related, and it is actually a pointer issue. However, I can't find where I'm going wrong.
Code:
#include <SDL/SDL.h>
struct image
[code]...
View 4 Replies
View Related
Nov 15, 2010
On this link [URL]4 a return type is defined
Code:
return ((unsigned int)(unsigned long)base & TBASE_DEFERRABLE_FLAG);
What is the above function returning.I am not clear with definition of what is being returned in the above code.
View 7 Replies
View Related
Jul 15, 2010
I'm getting some information about C language and this session of a C book (follow the above link) is using a bad example for me. When I'm trying this example of function returning a pointer, my compiler is stating a warning that I return a pointer to a local variable. I realized that it is error prone after all this variable may be override before the function has done his execution. And the author is fooling me saying that this example is "perfectly safe". I'm wrong? There is something that I don't got yet? Sorry but this site is preventing me to post the link of book cause I'm a newbie, so a need the hack it. Just strip out the question signs:
{LINK}
?w?w?w
?cs.cf.ac.uk?
[code]....
View 6 Replies
View Related
Jan 29, 2014
I going through the Python course on Codeacademy. I have some trouble understanding what I'm doing wrong. This is my code below:
Code: Select alldef count(sequence, item):
total = 0
for x in sequence:
return x
if x in sequence:
total += 1
return total
print count([1,2,1,1], 1 )
The code gives me an error: "Oops, try again. Your function fails on count([1],7). It returns 1 when it should return 0."
It should be outputting 3 because 1 occurs 3 times in the list.
View 7 Replies
View Related
Jan 21, 2011
I'm trying to write some code that involves creating a function to return a vector iterator.I'm not sure what is wrong.
Code:
template <typename T> class VectorTemplate
{
[code]....
View 4 Replies
View Related
Jul 31, 2010
I am exploring the Python 3 standard library and am currently attempting to test the bin function. It converts an integer into a binary string. I believe the module I wrote is flawed somehow. Here's the source code:
Code:
#!/usr/bin/python3.1
#This module tests the bin() function.
import sys
def get_input():
x = input("Enter an integer: ")
def use_bin():
[code]....
As you can see, the binary form given is always 0b10111. I'm no expert on binary code (or hexadecimal notation), but surely 9000 and two would have different results?
EDIT: Added a line in the module to repeat back what integer the user entered, and then the binary form. It would appear that no matter what integer the user enters, Python thinks it's "23".
Example output:
Code:
>>>
Enter an integer: 1
You entered 23
The binary form of this integer is 0b10111
>>>
View 3 Replies
View Related
Dec 28, 2010
If i have a python file with a function call_me(a,b),how can I call this function from the command line ,after i compile the program?
View 5 Replies
View Related
Jul 23, 2011
after upgrading ClamAV to version 0.97.1 and run the command Code: clamscan -r -i / --exclude-dir=^/sys --exclude-dir=^/dev --exclude-dir=^/proc | mail -s "clamav scan report XYSERVER" xy@mail.com the following errors appeared:
[Code].....
View 3 Replies
View Related
May 11, 2010
Is there a python equivalent for the "array_unique" function in php?
I have to run a query on a very large table (1.5 million records, with no index!) and php can't beat the max execution time. So I am converting my php script to python, which I have never used before.
my php script basically does this:
gets results from database
gets the number of unique values in column "X"
counts how many times each unique value in column "X" occurs
echos the results
My php script was originally running on a smaller version of the table, I would have started in python if I would have known the "real" table was so large, python is the only language I have access to in my current environment (besides php).
View 2 Replies
View Related
Dec 8, 2010
This is one of the strangest problems I've run into while programming. Maybe there's just something wrong with my version of gcc or something.
The main problem comes at this point in the code:
Code:
po = makePoFromScorbotXYZPR(X, Y, Z, P, R);
h = makeHB2GFromPo(po);
printf("%le", *h[1][0]); //##################################### Here it has the right value
printf("%s", "
[Code].....
View 2 Replies
View Related
Oct 17, 2015
I need to make a function combination to get for: If cell A1 then for B1 as:
A1 B1
--- ---
abc abc
hello hello
empty empty
0 0
-3 -3
5 5
and like wise
View 1 Replies
View Related
Nov 16, 2010
Code:
#include <iostream>
using namespace std;
[code]...
View 1 Replies
View Related
May 18, 2010
I am doing some Linux kernel programming for my research project. I need to record the timestamp (by using cpuid and rdtsc) when an interrupt handler (top half) is first invoked. Due to the time critical nature of the problem itself, I have to do the timestamping inside the interrupt handler itself (the first operation when the handler is called). However, I understand that tasks that are not so time critical should be deferred to a tasklet function (bottom half) for processing because other interrupts are disabled in a (top-half) interrupt handler. I am currently out of idea on how I can pass the timestamp information that I have obtained in the interrupt handler to the corresponding tasklet function.
View 2 Replies
View Related
Mar 22, 2009
I want to be able to do
sudo ./program.py
instead of always having to do
sudo python program.py
What do I need to change?
View 5 Replies
View Related
Nov 30, 2009
I've already used line split stuff to transform my data into something like this in a text file:
Code:
['1', '1', '3', '20.7505207']
['2', '1', '3', '23.0488319']
['3', '1', '3', '-1.5768747']
['4', '1', '3', '-26.4772491']
[code]....
How can I get this on a python program so I can manipulate it as an array?
View 3 Replies
View Related
May 14, 2010
I have an odd thing. And thats the following:
I entered: gcc raw.c -m32 -g -static -o raw
And I got:
I installed all bin32 libs I am on a x64 system.
View 6 Replies
View Related
Mar 4, 2010
I have a function definition in a Python 2.x script which take a tuple as one of its arguments, but 2to3 has no answers nor any of my searching on how to represent the same in Python 3.x
Code:
def blah(self, (string1, string2))
View 4 Replies
View Related
May 24, 2010
I want to declare a function in a function, but had no success till now, see the error code below and visit the project at sourceforge
[Code]...
View 14 Replies
View Related
Jun 30, 2010
I trying to write a UART(interfacing of serial devices) to linux machine but after I execute the following code to receive data I need to enter key (carriage return).... but I don't want to remove carriage return/enter key
[Code]....
View 13 Replies
View Related
Jun 20, 2010
I looked on the net for such function or example and didin't find anything, thus after having made one i guess it would be legitimate to drop it to see what others thinks of it.
#!/bin/bash
addelementtoarray()
{
local arrayname=$1
[code]....
View 10 Replies
View Related
Feb 9, 2011
I want that I click with the mouse on the video, it paused.I notice that there is "BaconVideoWidget" which I guess is the video rendering widget but it don't have signal named "clicked":
Code:
vd = totem_object.get_video_widget()
vd.connect("clicked", vd.hide)
[code]....
View 3 Replies
View Related
Oct 12, 2010
i am having two small issues with a function i have made.sorry if it is a mess, i am still learning bash.the first is calling the nonpersistssh function (second line) and assigning the return value to nonpersistdiag.the function returns 1, but nonpersistdiag seems to only contain 0. i am unsure on how to proceed.the second problem is the nested else clause on line 10. it is a syntactical error. how would i declare it correctly?
Code: function endsession(){
nonpersistdiag=$[nonpersistssh]# a function that returns an exit code
sudo /etc/init.d/ssh stop; sshdiag=$?
[code]....
View 6 Replies
View Related
Jun 3, 2011
What are the uses of return 0, return 1 and exit statements in C
View 4 Replies
View Related
Jan 18, 2010
I'm confused about what "echo $0" in a shell actually return. Consider these tests:
Code:
[root@e11apvl151 ~]# # Login shell:
[root@e11apvl151 ~]# echo $0
-bash
[root@e11apvl151 ~]# # Starting a new shell
[root@e11apvl151 ~]# bash
[root@e11apvl151 ~]# echo $0
bash
[root@e11apvl151 ~]# screen
[root@e11apvl151 ~]# echo $0
/bin/bash
Depending on wether the shell is a login shell, a regular shell, or a screen utility, I get different results.
View 8 Replies
View Related
Mar 15, 2011
I have a file:
979798707
787862348
766428634
I want to see if all the records in the file are present in the contents of the files of a particular directory.
Basically I want to say if grep doesn't return anything, then report.
For example in /tmp dir I have 4 files and flast 2 values (787862348 and 766428634) are present in the files of /tmp dir, but first one (979798707) is not. I want to echo that in a reporting file.
something like:
while read line
do
# if ! grep -rl $line /tmp
echo $line >> are_not_present
done < "myFile"
How do I achieve " if ! grep -rl $line /tmp"? That is, if the line is found by grep, then grep will print the output, but if grep does'nt find it, it will print nothing. How can I check if grep didn't find it (i.e. printed nothing)?
View 2 Replies
View Related
Dec 16, 2010
I'm reading a text file with fscanf using a loop until feof(inFile). How can I return to the top of the file? As in I have one loop that scans until the eof and then after it there's another loop and I want to start from the beginning of the file again scanning to the end of it. How do I get back there?
View 3 Replies
View Related