Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to write equivalent Python code of following Objective-C code using PyObjC. Not sure how to do? Any help would be highly appreciated on ow to bridge Objective-C code into Python.
#import <IOKit/pwr_mgt/IOPMLib.h>
...
// kIOPMAssertionTypeNoDisplaySleep prevents display sleep,
// kIOPMAssertionTypeNoIdleSleep prevents idle sleep
//reasonForActivity is a descriptive string used by the system whenever it needs
// to tell the user why the system is not sleeping. For example,
// "Mail Compacting Mailboxes" would be a useful string.
// NOTE: IOPMAssertionCreateWithName limits the string to 128 characters.
CFStringRef* reasonForActivity= CFSTR("Describe Activity Type");
IOPMAssertionID assertionID;
IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
kIOPMAssertionLevelOn, reasonForActivity, &assertionID);
if (success == kIOReturnSuccess)
{
//Add the work you need to do without
// the system sleeping here.
success = IOPMAssertionRelease(assertionID);
//The system will be able to sleep again.
}
...
you need to generate a bridge file for the IOKit.framework first using the gen_bridge_metadata command.
you can hard code the contents of the file into a Python variable if you want.
then load the bridge into into PyObjC using objc.parseBridgeSupport()
objc.parseBridgeSupport(BRIDGE_FILE_STRING, globals(), objc.pathForFramework("/System/Library/Frameworks/IOKit.framework"))`
examples here and here
Here is an example that does almost exactly what you are asking.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
so my python application opens a link that would be found in my config file. I would like to make it so it would like to allow it to go to the website without doubling the %. Heres what I would want config.get('CONFIG', 'Website') the web address has a bunch of %'s in the link but when I run it, the process ends
I'm assuming you are using the configparser module?
If so, you can use ConfigParser(interpolation=None) to disable string interpolation (which controls the behavior of % characters in the config file).
(Or on older versions of Python, you may need to use RawConfigParser instead.)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am new to python and am now learning about 'traceroute'. I don't exactly understand how this works. If I am typing the traceroute in python command line, I receive a syntax error:
traceroute www.somewebsite.com
I receive a syntax error pointing to ^www
Am I misunderstanding or doing something wrong? I'm trying to work on this in practice from a book reading assignment.
Can someone explain what traceroute is exactly?
Your help is appreciated, thank you.
This is not supposed to work, because python does not understand terminal/cmd commands. So you need to use os.system in this case:
So, in your case:
import os
os.system('traceroute www.somewebsite.com`)
In windows its tracert not traceroute.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I’m trying to print a string that is too long to be displayed on one line, so it automatically wraps to the next line. The problem is that I need it to all stay on one line and just go off the screen (where I can just scroll left to right to see it all).Is there a way to to disable word wrap in python IDLE
by changing somethings in configure option
Text wrapping is a function of your terminal, not python. All that python does is send a string to the terminal - think about it, when you say print "abcdef\n", there's no character in there that tells the terminal to wrap-text!
You just need to configure the environment you're coding in. There should be a pretty easily accessible 'settings' option. However, if you can't find it, then tell us what environment you're using - we might be able to help.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I am currently putting some code together to create a TCP/IP client which will have to communicate with an existing network server (Local not Internet). The server code is out of my control as it is already in place. I seem to have test code that works, at least the server recognises that a client with the relevant IP address is making a connection, however, on first connection the server sends out an Identify command to confirm the client is valid:
IDENTIFY_#
This is my problem. The client code has to be written in Python and obviously #'s seem to create an issue. My understanding (being new to Python) is that they are only used for comments and all of the posts and books I have read seem to say the same. Unfortunately I have to respond with strings that also possess #'s as termination characters for data sets so it makes things twice as problematic. Is it possible to get Python to recognise a # for what it is and not throw a wobbly because it assumes it is a comment?
If the # symbol is within a string literal, it shouldn't be interpreted as a comment.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
When I ctrl click a builtin function in my IDE I noticed I usually get sended to an init file which holds the function but it just returns the function again.. It states a vague doc string like 'original footprint unknown'
Where do I find the real functions ?
For example where is print_function
the specific example, print is defined in C, in the bltinmodule.c: specifically.
http://hg.python.org/cpython/file/3.3/Python/bltinmodule.c#l1518
More generally, functions implemented in C have no equivalent to the source file you would read in python; the C code is compiled into binary machine code, and no reference to where that bit of code might have come from is (usually) retained in the result; and even if there was, it's unlikely that you happen to have the source code installed in a place your IDE is likely to find it, unless you built it yourself, with debug symbols, and are running the C executable process in that ide's debugger.
Usually in the same directory where that file is. (Which I can't possibly know.)