Does Dart have some function or property that can tell whether the OS uses "/" or "\" in the file system paths, like File.separator in Java?
import 'dart:io';
Platform.pathSeparator
Small correction from previous answer.
import 'dart:io';
...
Platform.Platform.pathSeparator
See also Dart by example - Dart I/O and Command Line Apps - Getting the path separator for the current platform
Related
I'm trying to access spotify via the spotipy API from a win10 pro (64Bit) system.
In the spotipy documentation it says "...you can set environment variables like so:
export SPOTIPY_CLIENT_ID='your-spotify-client-id'" ...
Of cource I can use "var SPOTIPY_CLIENT_ID='your-spotify-client-id'" in my
script but I'd like to know what this export command means exactly.
Is that the export known from a Linux system?
I set the necessary spotify variables as environment variables in Win10 but they still were unknown.
Does anyone have an idea what it means exactly and how to get it working in win10?
Thanks
While it is better practice to set the environment variables if you just want to get up and running you can still pass in those values into the call in your code.
token = util.prompt_for_user_token(myUsername, scope, myClientId, mySecret, myRedirect)
There is info on wikipedia about how to set them.
Also refer to this StackOverflow answer.
I don't know if it will work for python scripts, but the windows commands you want would be:
SetX SPOTIPY_CLIENT_ID your-spotify-client-id
Souce: http://ss64.com/nt/setx.html
for windows 10 powershell terminal use $env: instead of export(for macs) and put your code string in quotes:
$env:SPOTIFY_CLIENT_ID="XXXX"
This is my code:
SoundPlayer player = new SoundPlayer("sound/music.wav");
player.Load();
player.Play();
The sound exists in directory, but when I build it, the program throws FileNotFoundException.
What should I do?
Make it a habit to always use System.IO.File.Exists() before actually asking .NET to use a file. This can save you from some run-time exceptions.
This is almost certainly because the relative path you have provided does not map to the current directory. I'm not even sure if that kind of forward-slash addresses is supported by SoundPlayer's constructor or by .NET in general. Anyway, you should always use System.IO.Directory functions to construct your full path and pass that to SoundPlayer.
What's the simplest way to find the path to the file in which I am "executing" some code? By this, I mean that if I have a file foo.py that contains:
print(here())
I would like to see /some/path/foo.py (I realise that in practice what file is "being executed" is complicated, but I think the above is well defined - a source file that contains some function that, when executed, gives the path to said file).
I have needed this in the past to make tests (that require some external file) self-contained, and I am currently wondering if it would be a useful way to locate some support files needed by a program. But I have never found a good way of doing this. The inspect module sounds like it should work, but you seem to need a class or function that is defined in that module.
In particular, the module instances contain __file__ attributes, but I can't see how to get the "current" module. Objects have a __module__ attribute, but that's the module name, not a module instance.
I guess one way is to throw and catch an exception and inspect the contents, but that seems like hard work. Surely there is a simple, easy way that I have missed?
To get the absolute path of the current file:
import os
os.path.abspath(__file__)
To get content of external file distributed with your package you could use pkg_util.get_data()(stdlib) or pkg_resources.resouce_string() (setuptools) to support execution from zip-archives or standalone executables created by py2exe, PyInstaller or similar, example.
I want to open a given file "directory/subdirectory/file.txt" in golang. What is the recommended way to express such a path in an OS agnostic way (ie backslashes in Windows, forward slashes in Mac and Linux)? Something like Python's os.path module?
For creating and manipulating OS-specific paths directly use os.PathSeparator and the path/filepath package.
An alternative method is to always use '/' and the path package throughout your program. The path package uses '/' as path separator irrespective of the OS. Before opening or creating a file, convert the /-separated path into an OS-specific path string by calling filepath.FromSlash(path string). Paths returned by the OS can be converted to /-separated paths by calling filepath.ToSlash(path string).
Use path/filepath instead of path. path is intended for forward slash-separated paths only (such as those used in URLs), while path/filepath manipulates paths across different operating systems.
Example:
package main
import (
"fmt"
"path/filepath"
)
func main() {
path := filepath.Join("home", "hello", "world.txt")
fmt.Println(path)
}
Go Playground: https://go.dev/play/p/2Fpb_vJzvSb
Based on the answer of #EvanShaw and this blog the following code was created:
package main
import (
"fmt"
"os"
"path/filepath"
)
func main() {
p := filepath.FromSlash("path/to/file")
fmt.Println("Path: " + p)
}
returns:
Path: path\to\file
on Windows.
Go treats forward slashes (/) as the universal separator across all platforms [1]. "directory/subdirectory/file.txt" will be opened correctly regardless of the runtime operating system.
Can I somehow tell GStreamer to look for plugins in a specified directory?
Use the GST_PLUGIN_PATH environment variable to point at the directory you want, or programatically just call:
GstRegistry *registry;
registry = gst_registry_get();
gst_registry_scan_path(registry, directory);
You can no longer do this programmatically in gstreamer 1.0.
In the above answer,
gst_registry_get_default() was replaced with gst_registry_get()
and gst_registry_add_path() was removed.
You can also set GST_PLUGIN_SYSTEM_PATH to the location of the Plugins. Not sure what the difference is between this and GST_PLUGIN_PATH though.
In case you are running GStreamer from command line you may add --gst-plugin-path=PATHS to the command
Example adding current directory as plugins path
gst-inspect-1.0 kvssink --gst-plugin-path=$PWD
There is much more useful commands available just check:
gst-launch-1.0 --help-gst